Question:
I’ve got ten pages of code and there’s an “If” on the first page, a bunch of “If…EndIf” statements throughout the code and the “EndIf” that corresponds with the first “If” lurks somewhere below. Short of just looking for the last “EndIf” (which would work in this case), I’d like to know how to find *any* block closing statement. That is, what’s the trick to finding a corresponding “EndIf”, “Wend”, etc. If the built-in module editor won’t cut it I’m open to suggestions for other editors.
Answer:
Unfortunately, there is no easy way to find the closing EndIf (or otherkeyword) statement. However, good code formatting is often a good solutionfor this problem. For each If/For/other keywords, indent all of the linesbelow it. As soon as you add the opening keyword, put in the closing oneand add a comment indicating which keyword the end one belongs to, as inthis example:
If i > 10 Then … lots of code …End If ‘ If i > 10This should help you find the ends of your loops. The other option, if itis possible, is to break the logical sections into subroutines, into whichyou pass the necessary variables.