a "do nothing" statement

  • Thread starter Thread starter craig
  • Start date Start date
C

craig

is there any type of statement that can be executed in
VBA, but essentially "does nothing"? this could be used
for breaking out of an IF statement or a WHILE loop

in C++ i thought the statement was "break", but I don't
know what its equivalent is in VBA. any help would be
appreciated.

thanks
 
you could use the Exit Function or Exit Sub...Wrap a
conditional if statement around it and when the condition
is met the code will hit that line and exit out of the
code. Something like

Dim X As Boolean
X = True
Do While X = True
Exit Function
X = False
Loop
 
is there any type of statement that can be executed in
VBA, but essentially "does nothing"?

You can simply leave that part of the construct empty.

If intMaxCount < 30 Then

Else

MsgBox "Value of max is 30 or more!!"

End If
this could be used
for breaking out of an IF statement or a WHILE loop

Now, the above is a different question and issue!

for i = 1 to 20

if i = 15 then
exit for <----- break out to stament after next i
endif

next i

For a while loop, you use exit do

Do While intI < 30

intI = intI + 1

If intI = 15 Then
Exit Do <--- break out to statement after loop
End If

Loop
 
Hi Craig,

There isn't a specific VBA statement for breaking out of a block, but
there is always GoTo

Dim j As Long, k As Long

For j = 1 To 99
k = f(j)
If k < 0 Then GoTo Last:
Next
Last:
Debug.Print "At Last: " & j

Otherwise, you can do things like

j = 0
k = 0
Do
j = j + 1
k = f(j)
Until (j = 99) Or (k < 0)
Debug.Print "Out of Loop: " & j
 
I was three quarters wrong: as Albert says, there's Exit For and Exit Do
.... but not an Exit If.
 
Back
Top