Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have a for next looping in vba that had many if and Do Until in it, but not embedded. I'd like to say to the loop "Next i" in a If condition if this If condition in the beginning in the loop is respected. Is there a way to do so? Thx ! JJD -- Message posted via http://www.officekb.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi. If I understand it correctly, is this something that would work?
Sub Demo() Dim J As Long For J = 1 To 10 ' do something If J 2 Then Exit For Next J End Sub HTH. :) -- Dana DeLouis Win XP & Office 2003 "Jean-Jerome Doucet via OfficeKB.com" wrote in message ... Hi, I have a for next looping in vba that had many if and Do Until in it, but not embedded. I'd like to say to the loop "Next i" in a If condition if this If condition in the beginning in the loop is respected. Is there a way to do so? Thx ! JJD -- Message posted via http://www.officekb.com |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Not exactly but you understand the way I think. I want to say Next and not
exit Sub Demo() Dim J As Long For J = 1 To 10 ' do something If J 2 Then Exit For ' it would be there an alternative Next J then it skips all the rest of the code in this loop J and go to the next J Do Unit 'A lot of do something after the If but not related to the If and not embedded with it. Next J End Sub Dana DeLouis wrote: Hi. If I understand it correctly, is this something that would work? Sub Demo() Dim J As Long For J = 1 To 10 ' do something If J 2 Then Exit For Next J End Sub HTH. :) Hi, [quoted text clipped - 8 lines] JJD -- Message posted via http://www.officekb.com |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub Demo()
Dim J As Long For J = 1 To 10 ' do something If Cells(1,J).Value 2 then ' code to process the cell End if Next J End Sub -- Regards, Tom Ogilvy "Jean-Jerome Doucet via OfficeKB.com" wrote in message ... Not exactly but you understand the way I think. I want to say Next and not exit Sub Demo() Dim J As Long For J = 1 To 10 ' do something If J 2 Then Exit For ' it would be there an alternative Next J then it skips all the rest of the code in this loop J and go to the next J Do Unit 'A lot of do something after the If but not related to the If and not embedded with it. Next J End Sub Dana DeLouis wrote: Hi. If I understand it correctly, is this something that would work? Sub Demo() Dim J As Long For J = 1 To 10 ' do something If J 2 Then Exit For Next J End Sub HTH. :) Hi, [quoted text clipped - 8 lines] JJD -- Message posted via http://www.officekb.com |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom, I don't see how it solvesmy problem. It is a regular for next you
presented me here. I want to put a line code that specify in another place (in the if) to do Next J with arriving to the official Next J. It the same principle as Exit For, excepted that I don't want to exit but to go to the next J. Tom Ogilvy wrote: Sub Demo() Dim J As Long For J = 1 To 10 ' do something If Cells(1,J).Value 2 then ' code to process the cell End if Next J End Sub Not exactly but you understand the way I think. I want to say Next and not exit [quoted text clipped - 28 lines] JJD -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200507/1 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That is exactly what I gave you.
If you want something more obscene Sub Demo() Dim J As Long For J = 1 To 10 ' do something If Cells(1, J).Value 2 Then GoTo Line3 ' code to process the cell Debug.Print J Line3: Next J End Sub Welcome to the 70's -- Regards, Tom Ogilvy "Jean-Jerome Doucet via OfficeKB.com" wrote in message ... Tom, I don't see how it solvesmy problem. It is a regular for next you presented me here. I want to put a line code that specify in another place (in the if) to do Next J with arriving to the official Next J. It the same principle as Exit For, excepted that I don't want to exit but to go to the next J. Tom Ogilvy wrote: Sub Demo() Dim J As Long For J = 1 To 10 ' do something If Cells(1,J).Value 2 then ' code to process the cell End if Next J End Sub Not exactly but you understand the way I think. I want to say Next and not exit [quoted text clipped - 28 lines] JJD -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200507/1 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What you are asking to do is have another Next statement within the If block.
No Can Do. For-Next statements must be balanced, and within the same nested level. Dim J As Long For J = 1 To 10 ' do something If Cells(1,J).Value 2 then ' code to process the cell Next J <---------- you want to put another Next statement here? End if Next J Nope. Even if it did work it would be poor program structure. Try reorganizing your If-Then-Else blocks, or use the Select statement so that whatever is performed in the desired block of code exits just before the Next statement. "Jean-Jerome Doucet via OfficeKB.com" wrote: Tom, I don't see how it solvesmy problem. It is a regular for next you presented me here. I want to put a line code that specify in another place (in the if) to do Next J with arriving to the official Next J. It the same principle as Exit For, excepted that I don't want to exit but to go to the next J. Tom Ogilvy wrote: Sub Demo() Dim J As Long For J = 1 To 10 ' do something If Cells(1,J).Value 2 then ' code to process the cell End if Next J End Sub Not exactly but you understand the way I think. I want to say Next and not exit [quoted text clipped - 28 lines] JJD -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200507/1 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Looping | Excel Discussion (Misc queries) | |||
Looping | Excel Discussion (Misc queries) | |||
Looping | Excel Programming | |||
Looping | Excel Programming | |||
looping to End | Excel Programming |