0

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!

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.