I want to loop over the values in a range on my ActiveWorksheet (Sheet1) and compare them to values in a range on another worksheet (Sheet2).
Here's my original code:
This gives me "runtime error 1004"
Here's two test bits of code :
This works.
This gives me "runtime error 1004"
How can I achieve my goal and why does my first test code work while my second test code fails?
Here's my original code:
Code:
Sub LoopOverRange()
Dim fromColumn As range
Dim toColumn As range
Set fromColumn = Sheet1.range("C2", range("C20000").End(xlUp))
Set toColumn = Sheet2.range("A2", range("A20000").End(xlUp))
For Each c In fromColumn.Cells
If c <> "null" Then
For Each d In toColumn.Cells
If c.Value = d.Value Then
Call doSomething(c, d)
End If
Next
End If
Next
End Sub
Here's two test bits of code :
Code:
Sub testRange()
Dim myRange As range
Set myRange = Sheet1.range("C2", range("C20000").End(xlUp))
End Sub
Code:
Sub testRange()
Dim myRange As range
Set myRange = Sheet2.range("C2", range("C20000").End(xlUp))
End Sub
How can I achieve my goal and why does my first test code work while my second test code fails?