Solved

Problem to skip loop

Posted on 2016-09-08
6
48 Views
Last Modified: 2016-09-08
Hi,
I want to skip the loop below, per relevant conditions are matched
    Do While True
        ...

            If Trim(Worksheets(List0).Cells(RowID, 8).Value) <> "" And InStr(User_List, ";" & Trim(Worksheets(List0).Cells(RowID, 8).Value)) = 0 Then Continue Do
            End If

Open in new window

but I get 'Syntax Error' due to 'Continue Do'. What to adjust?
0
Comment
Question by:HuaMinChen
6 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
Exit do is used to skip loop

do while condition
     if certain condition then
             exit do
     endif
loop
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
If you want to leave the Do loop then use Exit Do
0
 
LVL 10

Author Comment

by:HuaMinChen
Comment Utility
No, I only want to skip one iteration, and not to leave the whole loop.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 31

Assisted Solution

by:Rob Henson
Rob Henson earned 100 total points
Comment Utility
In which case just have an If statement within your Do Loop:

Do
  If Condition Then
    Code 1
  Else
    Code 2
  End If
Loop

Alternatively you could use the Select Case format within the Do Loop.
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 400 total points
Comment Utility
Using your syntax

Since you also have an "End If" then there should be nothing after the "Then" in the same line. It should go to the next line.
If you put no code after "Then" it will automatically continue with the do loop. You do not have to tell it to do so.
The "Else" is to handle the other condition not satisfied by the if.

    Do While True
        ...

            If Trim(Worksheets(List0).Cells(RowID, 8).Value) <> "" And InStr(User_List, ";" & Trim(Worksheets(List0).Cells(RowID, 8).Value)) = 0 Then 

            else
                    do what you want to do otherwise
            End If

Open in new window

0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
Looks like you are not fully satisfied with the answer.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
My experience with Windows 10 over a one year period and suggestions for smooth operation
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now