SmC
SmC

Reputation: 3

VBA: 'Next i' followed by 'Exit For'

I have started a new job which involves some VBA programming. I have inherited some code which is used for extracting data from a program used in the office. I am new to VBA and I am trying to interpret this code. My issue lies in a for loop where it is finished by 'Next i' and then subsequently an 'Exit For'. I cannot find any examples of this online and unfortunately the code was not indented. My question is whether this is correct procedure in VBA? It seems incorrect to me as the 'Next i' terminates the for loop. The code performs ok, however I am changing its functionality and I am running into some issues.

With Rflct(z)

    'Long stem of code here... there are no for loops in this code'

    For i = 1 To 8

        'Long stem of code here... there are no for loops in this code'

    Next i
    Exit For
End With

I have added the indentations where I deemed correct, Thank you!

Upvotes: 0

Views: 545

Answers (1)

arcadeprecinct
arcadeprecinct

Reputation: 3777

If you don't get a compile error, that Exit For belongs to another (higher up) For loop. Indent the code properly and you should be able to find it (more) easily. It is also probably within an If scope inside that For loop.

Upvotes: 2

Related Questions