Link to home
Create AccountLog in
Microsoft Excel

Microsoft Excel

--

Questions

--

Followers

Top Experts

Avatar of lucavilla
lucavilla🇮🇹

continue a "do while" loop in VBA/Excel
do while .....
 ......
 If InStr("abc", "b") > 0 Then continue Loop
 ......
loop

Open in new window


I get "Compile error:   Expected: expression".

What's the problem?

If I remove "Loop" I receive another error...

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Rory ArchibaldRory Archibald🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Dale FyeDale Fye🇺🇸

generally, the code inside your loop will exit the loop when a condition is met, something like:
do while .....
 ......
     If InStr("abc", "b") = 0 Then Exit Do
 ......
loop

Open in new window


This would cause the code to jump to the next line outside of the loop.  If "b" is found in "abc", then the code inside the loop would continue.  The key is making sure that the code inside the loop provides one of two things:

1.  a way to jump out of the loop and continue processing
2.  a way to exit the subroutine (Exit Sub) or function (Exit Function)

Avatar of lucavillalucavilla🇮🇹

ASKER

no I just need to jump the case where the InStr returns > 0, continuing the loop to the next case  (not exiting the loop)

Avatar of Rory ArchibaldRory Archibald🇬🇧

That's what my answer assumed. ;)

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


SOLUTION
Avatar of Frank HelkFrank Helk🇩🇪

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of lucavillalucavilla🇮🇹

ASKER

Thanks guys!
Microsoft Excel

Microsoft Excel

--

Questions

--

Followers

Top Experts

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.