Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem to skip loop

Posted on 2016-09-08
6
63 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
ID: 41789181
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
ID: 41789182
If you want to leave the Do loop then use Exit Do
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 41789187
No, I only want to skip one iteration, and not to leave the whole loop.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 100 total points
ID: 41789190
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
ID: 41789200
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
ID: 41790715
Looks like you are not fully satisfied with the answer.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

840 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