ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Stumped (https://www.excelbanter.com/excel-programming/348656-stumped.html)

Andibevan[_4_]

Stumped
 
Hi,

If I try the following I get a Next without For error - Is it possible to do
something like this?


Sub test_loop()

For k = 1 To 5

If k = 3 Then
Next k
Else
MsgBox k
End If

Next k
End Sub

TIA

Andy



Kevin O'Neill[_2_]

Stumped
 
What are you trying to do exactly?


Tom Ogilvy

Stumped
 
Sub test_loop()

For k = 1 To 5

If k < 3 Then
MsgBox k
End If

Next k
End Sub

--
Regards,
Tom Ogilvy


"Andibevan" wrote in message
...
Hi,

If I try the following I get a Next without For error - Is it possible to

do
something like this?


Sub test_loop()

For k = 1 To 5

If k = 3 Then
Next k
Else
MsgBox k
End If

Next k
End Sub

TIA

Andy





Gary Keramidas

Stumped
 
this will even skip 3, but don't know what you're trying to accomplish

Sub test_loop()
Dim k As Long
For k = 1 To 5

If k = 3 Then
'do nothing
Else
MsgBox k
End If

Next k
End Sub


--


Gary


"Andibevan" wrote in message
...
Hi,

If I try the following I get a Next without For error - Is it possible to
do
something like this?


Sub test_loop()

For k = 1 To 5

If k = 3 Then
Next k
Else
MsgBox k
End If

Next k
End Sub

TIA

Andy





Andibevan[_4_]

Stumped
 
Sorry - I essentially was wondering whether it was possible to include two
'Next' Statements in one For loop?

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this will even skip 3, but don't know what you're trying to accomplish

Sub test_loop()
Dim k As Long
For k = 1 To 5

If k = 3 Then
'do nothing
Else
MsgBox k
End If

Next k
End Sub


--


Gary


"Andibevan" wrote in message
...
Hi,

If I try the following I get a Next without For error - Is it possible

to
do
something like this?


Sub test_loop()

For k = 1 To 5

If k = 3 Then
Next k
Else
MsgBox k
End If

Next k
End Sub

TIA

Andy







Dominic

Stumped
 
No, it is not.

It would help to know what you are trying to do, as Kevin O'Neill asked.

If you are trying to increase k by two through using two next statements,
then use step 2 in your for loop.

ex. for k = 1 to 5 step 2




"Andibevan" wrote:

Sorry - I essentially was wondering whether it was possible to include two
'Next' Statements in one For loop?

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this will even skip 3, but don't know what you're trying to accomplish

Sub test_loop()
Dim k As Long
For k = 1 To 5

If k = 3 Then
'do nothing
Else
MsgBox k
End If

Next k
End Sub


--


Gary


"Andibevan" wrote in message
...
Hi,

If I try the following I get a Next without For error - Is it possible

to
do
something like this?


Sub test_loop()

For k = 1 To 5

If k = 3 Then
Next k
Else
MsgBox k
End If

Next k
End Sub

TIA

Andy








Dana DeLouis[_3_]

Stumped
 
If I try the following I get a Next without For error - Is it possible to
do
something like this?


Hi. You have two "Next" statements, therefore your error. Here are just
two of many ways:

Sub test_loop1()
Dim k As Long
For k = 1 To 5
If k = 3 Then
'Remark: Do Nothing...
Else
MsgBox k
End If
Next k
End Sub


Sub test_loop2()
Dim k As Long
For k = 1 To 5
If k < 3 Then MsgBox k
Next k
End Sub

HTH :)
--
Dana DeLouis
Win XP & Office 2003


"Andibevan" wrote in message
...
Hi,

If I try the following I get a Next without For error - Is it possible to
do
something like this?


Sub test_loop()

For k = 1 To 5

If k = 3 Then
Next k
Else
MsgBox k
End If

Next k
End Sub

TIA

Andy






All times are GMT +1. The time now is 01:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com