title: in vba how to define array and compare them?
body: <p>i have 2 sheets , i want to find the same rows in 2 sheets , so i put the first row in array , and by a for next i define the first array ...then i define another array from second sheet , then i compare them .... why it doesn't work?  </p>
  
  <pre><code>Sub compare()
      Dim n(4) As Variant
      Dim o(4) As Variant
      Dim i As Integer
  
      For i = 3 To 20    'satrha
          For j = 2 To 4     'por kardan
              n(j) = Sheets("guys").Cells(i, j)
          Next                'por kardan
          k = 3
          Do                  'hhhh
              For Z = 2 To 4     'por dovomi
                  o(Z) = Sheets("p").Cells(k, Z)
              Next                  'por dovomi
              If n(j) = o(Z) Then
                  Sheets("guys").Cells(i, 1) = Sheets("p").Cells(k, 2)
                  flag = True
              Else
                  flag = False
                  k = k + 1
              End If
          Loop Until flag = False  'hhhhh
      Next             'satrha
  End Sub
  </code></pre>