I am getting a "Next Without for Error on the following code:
sub test()
numRows = 11
For i = 0 To numRows
If Cells(i + 1, 2) >= 0 Then
Range((Cells(A, i + 1)), Cells(B, i + 1)).Select
Selection.Copy
Sheets("PasteLocation").Activate
Range("Ai+1").Select
Selection.Paste
Next
End Sub
I assume that my "If" statement doesnt know that it's done and that the "Next" command thinks there should be another nested "for" in the "if" statement but I do not know where.
IfwithEnd If. If then Else Excel VBA - "End If" needed?Range("Ai+1").SelectIfblock but never terminate it - hence the compiler "thinks"Nextis part of theIfblock, can't find a correspondingForstatement, and blows up saying exactly that: there's aNextstatement that shouldn't be there. All block syntax work the same way, and they can't be intertwined (i.e. you can't start aForloop, begin anIfblock, then close theForloop with aNext, and then somewhere further down close theIfblock withEnd If)