Use of "Continue" keyword giving compile time error

Tejas Kore

Board Regular
Joined
Nov 2, 2017
Messages
72
Office Version
  1. 365
Platform
  1. Windows
Hi Friends,

I am bit confused as this keyword("continue") exits or not in VBA. Then after googling I found this link
https://docs.microsoft.com/en-us/dotnet/visual-basic/language.../continue-statement

Here they have mentioned the use of this keyword. But when I tried to implement that it is giving error.

Here in the below code I have used [MsgBox ("Skipping")].Here I actually want to skip the iteration.
How can I achieve this ?

Sub test()


names1 = Array("Fox", "Elephant", "Rat")
For Each strsearch In names1
If strsearch Like "*an*" Then
MsgBox ("Skipping") 'Want to go to next iteration
Else
MsgBox (strsearch)
End If
Next strsearch
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi,
Continue Keyword I personally, have never known to exist in VBA but perhaps another here may know differently.

You can use the Not Operator which may give result you are looking for

Rich (BB code):
Sub test()
    
    names1 = Array("Fox", "Elephant", "Rat")
    For Each strsearch In names1
        If Not strsearch Like "*an*" Then
            MsgBox ("Skipping") 'Want to go to next iteration
        Else
            MsgBox (strsearch)
        End If
    Next strsearch
        
End Sub

Dave
 
Upvote 0
Continue is not valid in VBA. You can simply not put anything in the If block, or use Not as Dave suggested.
 
Upvote 0
Thanks a LOT Rory And Dave !!!.
I chose the other option of writing nothing for implement this functionality in my code. Actually the link which I took reference of , which I have pasted above ,I got confused because of that .
And Thanks again for telling how to use 'Not'. I was using 'Like Not' which was giving compile time error again and again:( .
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top