Link to home
Start Free TrialLog in
Avatar of Peter Chan
Peter ChanFlag for Hong Kong

asked on

Problem to line

Hi,
I get syntax error to this line
        If (Trim(ConfigWS.Cells(i, "D").Value) = "") Then Continue For

Open in new window

within one For loop. why?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

"Continue For" is not really a proper syntax, if it's a comment, try:
If (Trim(ConfigWS.Cells(i, "D").Value) = "") Then //Continue For

Open in new window

or
If (Trim(ConfigWS.Cells(i, "D").Value) = "") Then
     //Continue For
    
End if

Open in new window

Looks good but

1/ Is the value "i" declared and an integer or long type
2/ Has ConfigWS been created as a worksheet object

What exact error are you getting?

A single line of code often does not give us the information to correctly analyse the issue and so posting the workbook or at least posting the entire function will help us in resolving the issue
Avatar of Peter Chan

ASKER

I want to skip the loop, within If. What to adjust?
Yeah, "Continue For" isn't proper syntax.

Instead of looking to continue, look for something to not continue and perform your action....

For i = 1 To 100
    If Trim(ConfigWS.Cells(i, "D").Value) <> "" Then
        'Do your thing
    End If
End if

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Continue For is part of Visual Studio 2015.
If this is VBA, then you will need to do what I describe in this Next Iteration article:
http://rdsrc.us/VCFFaB

// is not a valid comment indicator in VBA
>>// is not a valid comment indicator in VBA
exactly Aikimark... thks for highlighting, was posted too quickly and still thinking to code in C# environment...

we should use ' instead for commenting in VBA.
exit is not the same as continue. Do you want to stop the loop (and continue with execution after the loop) or skip this loop iteration (and continue with the next loop value)?