Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default For/Loop skipping one value in loop only

G'day guys and girls
Just a quick question, more general programming than VBA specific, and one
that I haven't had to deal with before in any programming.

Example (pseudo code):

For i = 1 to 6
if myvar = true then
if i = 3 then
skip to next i
else
'do my code
end if
end if
Next i

So, in simple terms, I want to skip my processing code if i = 3.
However I included the "if myvar = true" code because I only want to skip
i=3 if a certain condition elsewhere in my workbook is true.

What's the best way to go about this?
Thanks very much
Matt


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default For/Loop skipping one value in loop only

Hi Matt,

One way:

For i = 1 To 6
If i = 3 And myvar = True Then
'do nothing
Else
'do my code
End If
Next

---
Regards,
Norman



"Matt Jensen" wrote in message
...
G'day guys and girls
Just a quick question, more general programming than VBA specific, and one
that I haven't had to deal with before in any programming.

Example (pseudo code):

For i = 1 to 6
if myvar = true then
if i = 3 then
skip to next i
else
'do my code
end if
end if
Next i

So, in simple terms, I want to skip my processing code if i = 3.
However I included the "if myvar = true" code because I only want to skip
i=3 if a certain condition elsewhere in my workbook is true.

What's the best way to go about this?
Thanks very much
Matt




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default For/Loop skipping one value in loop only

This really does not make any diff, maybe you are trying to increment i from
3 to 5? In that case instead of SkipDow put i = i +1?

Sub SkipIT()
myvar = True
For i = 1 To 6
If myvar = True Then
If i = 3 Then
GoTo SkipDown
Else
'do my code
End If
End If
SkipDown:
Next i
End Sub


"Matt Jensen" wrote:

G'day guys and girls
Just a quick question, more general programming than VBA specific, and one
that I haven't had to deal with before in any programming.

Example (pseudo code):

For i = 1 to 6
if myvar = true then
if i = 3 then
skip to next i
else
'do my code
end if
end if
Next i

So, in simple terms, I want to skip my processing code if i = 3.
However I included the "if myvar = true" code because I only want to skip
i=3 if a certain condition elsewhere in my workbook is true.

What's the best way to go about this?
Thanks very much
Matt



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default For/Loop skipping one value in loop only

Hah! Excellent thanks guys - too easy!
My brain's a bit fried at the moment and my eyes are almost square from so
much time in front of the screen this week, so the heads up is much
appreciated...!
Thanks again
Cheers
Matt

"David" wrote in message
...
This really does not make any diff, maybe you are trying to increment i

from
3 to 5? In that case instead of SkipDow put i = i +1?

Sub SkipIT()
myvar = True
For i = 1 To 6
If myvar = True Then
If i = 3 Then
GoTo SkipDown
Else
'do my code
End If
End If
SkipDown:
Next i
End Sub


"Matt Jensen" wrote:

G'day guys and girls
Just a quick question, more general programming than VBA specific, and

one
that I haven't had to deal with before in any programming.

Example (pseudo code):

For i = 1 to 6
if myvar = true then
if i = 3 then
skip to next i
else
'do my code
end if
end if
Next i

So, in simple terms, I want to skip my processing code if i = 3.
However I included the "if myvar = true" code because I only want to

skip
i=3 if a certain condition elsewhere in my workbook is true.

What's the best way to go about this?
Thanks very much
Matt





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default For/Loop skipping one value in loop only

Except that the "purists" will tell you that the variable used in a For/Next
loop should be modified ONLY by the NEXT statement. If you adhere to those
"rules", Matt's solution is what is needed.

On Thu, 6 Jan 2005 08:25:02 -0800, "David"
wrote:

This really does not make any diff, maybe you are trying to increment i from
3 to 5? In that case instead of SkipDow put i = i +1?

Sub SkipIT()
myvar = True
For i = 1 To 6
If myvar = True Then
If i = 3 Then
GoTo SkipDown
Else
'do my code
End If
End If
SkipDown:
Next i
End Sub


"Matt Jensen" wrote:

G'day guys and girls
Just a quick question, more general programming than VBA specific, and one
that I haven't had to deal with before in any programming.

Example (pseudo code):

For i = 1 to 6
if myvar = true then
if i = 3 then
skip to next i
else
'do my code
end if
end if
Next i

So, in simple terms, I want to skip my processing code if i = 3.
However I included the "if myvar = true" code because I only want to skip
i=3 if a certain condition elsewhere in my workbook is true.

What's the best way to go about this?
Thanks very much
Matt






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default For/Loop skipping one value in loop only

Myrna Larson wrote:
Except that the "purists" will tell you that the variable used in a For/Next
loop should be modified ONLY by the NEXT statement. If you adhere to those
"rules", Matt's solution is what is needed.


What is the argument in favor of the "purists' rules"?

Alan Beban
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default For/Loop skipping one value in loop only

Yeah I'm not too sure which solution Myrna is referring to, I imagine it was
David's though...?
Matt

"Myrna Larson" wrote in message
...
Except that the "purists" will tell you that the variable used in a

For/Next
loop should be modified ONLY by the NEXT statement. If you adhere to those
"rules", Matt's solution is what is needed.

On Thu, 6 Jan 2005 08:25:02 -0800, "David"


wrote:

This really does not make any diff, maybe you are trying to increment i

from
3 to 5? In that case instead of SkipDow put i = i +1?

Sub SkipIT()
myvar = True
For i = 1 To 6
If myvar = True Then
If i = 3 Then
GoTo SkipDown
Else
'do my code
End If
End If
SkipDown:
Next i
End Sub


"Matt Jensen" wrote:

G'day guys and girls
Just a quick question, more general programming than VBA specific, and

one
that I haven't had to deal with before in any programming.

Example (pseudo code):

For i = 1 to 6
if myvar = true then
if i = 3 then
skip to next i
else
'do my code
end if
end if
Next i

So, in simple terms, I want to skip my processing code if i = 3.
However I included the "if myvar = true" code because I only want to

skip
i=3 if a certain condition elsewhere in my workbook is true.

What's the best way to go about this?
Thanks very much
Matt






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Loop Ben Allen Excel Programming 1 May 21st 04 12:07 PM
Do Until Loop pikus Excel Programming 1 May 11th 04 08:46 PM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"