Compile error: Next without For || VBA

Every For statement with a body must have a matching Next, and every If-Then statement with a body must have a matching End If.

Example:

For i = 1 To 10 '<---- This is the header

    Hello(i) = "Blah"  '<---- This is the body

Next i  '<---- This is the closing statement

You have part of the body of your If statement inside your For i loop, and part of it outside. It has to be either ALL inside or ALL outside. Think through the logic and see what it is you want to do.

Leave a Comment