title: Iterating over a collection (VBA)
body: <p>Hello I am new to VBA and I am trying to iterate over a collection i've made and execute an action for each value.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Sub makeRowsMatch()
  
  Dim rows As VBA.Collection
  Set rows = New VBA.Collection
  
  Dim i As Integer
  Dim j As Integer
  Dim y As Integer
  
  
  For i = 2 To 22203
  For j = 2 To 121
  
  If Cells(i, 2).Value &lt;&gt; Cells(j, 38) Then
       rows.Add (i)
  
  End If
  
  Next j
  Next i
  
  
  For Each y As Object in rows
  rows(y).Delete
  
  Next y
  
  End Sub
  </code></pre>
  
  <p>I keep on getting an error in the line: </p>
  
  <pre><code>For Each y As Object in rows
  </code></pre>
  
  <p>It keeps on getting highlighted yellow, but when I remove the above line is get the following error:</p>
  
  <pre><code>For Each control variable must be Variant or Object
  </code></pre>
  
  <p>Could someone explain why it is not letting me iterate over the values?
  The whole issue of declaring variables is new to me.
  Thanks!</p>