Reputation: 309
I am trying to write an excel macros using a loop to go through two columns of dates, comparing the dates in excel and replace some values in another column if the dates are the same.
This is my excel code, could someone tell me what is wrong with it? I keep getting the error Loop without Do.
Sub automatic_replace_using_do_while_loop()
Dim A As Integer, H As Integer
A = 1
H = 1
Do While H < 1186
If Cells(A, 1).Value = Cells(H, 8).Value Then
Cells(H, 6).Value = Cells(i, 11)
H = H + 1
A = A + 1
Else
H = H + 1
Loop
End Sub
Thanks!
Upvotes: 0
Views: 803
Reputation:
That isn't the way I would try to match dates but you never ended your If statement.
Do While H < 1186
If Cells(A, 1).Value = Cells(H, 8).Value Then
Cells(H, 6).Value = Cells(i, 11)
H = H + 1
A = A + 1
Else
H = H + 1
END IF
Loop
I don't know where i
comes into play. I think you meant
Cells(H, 6).Value = Cells(A, 11)
Upvotes: 2