Forum Discussion
How do we properly exit a vba loop and branch elsewhere in an excel userform?
LemonPeeler wrote: ``The problem is that when we use a GOTO statement to branch to another location, the Excel VBA compiler is showing errors like 'Compile error: end if without block if" or 'Compile error: next without block for".``
I doubt that that alone is the cause of the compiler error. And the literal text of the error message might be misleading. Ostensibly, you have a misplaced End IF or Next statement. But the real problem might be something different altogether.
You have a lot of narrative, which actually tells us very little. But "a picture is worth a 1000 words; and an Excel file is worth 1000 pictures".
At the very least, show us the entire VBA procedure, in one form or another. In this case, text is better than image, IMHO. It allows us to copy-and-paste the code in to our own VBA.
Even better, attach an Excel file that demonstrates the problem. Click the "browse" link near the bottom of the reply window. If the forum does not permit that (yet), upload the file to a file-sharing website, and post the download URL. I like box.net/files; others like dropbox.com.
If the forum does not permit you to post a URL (yet), spell out part of it manually. For example, the URL for this thread is techcommunity dot microsoft dot com /t5/excel/how-do-we-properly-exit-a-vba-loop-and-branch-elsewhere-in-an/m-p/3609626.