View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jean-Jerome Doucet via OfficeKB.com Jean-Jerome Doucet via OfficeKB.com is offline
external usenet poster
 
Posts: 17
Default Next For looping in a If

Well, I have found a way yo bypass the problem. And I think it will probably
be a cleaner solution as trying to put another Next J as you say Charlie ;) I
embedded all the rest of the code after the If with a Do Until and If the
condition If is fullfilled at the begginning a boolean variable becomes False.
So it says Do Until boolean variable is False. As it is already False it will
skip all this part of the code.

Tom, I found your code most interesting though, the one with the instruction
to go to Line3.

Thanks to both of you for your help. I'll include the logic I've used finally
at the end of this message.

Regards,

JJD

Sub Demo()
Dim J As Long
For J = 1 To 10
' do something
If variable = "N" Then ("N" for new)
Bool = False
Else
Bool= True
End If

Do Until Bool = False
'Here is all the rest of the Do and If conditions of the Next
For loop.
Bool = False 'My boolean value becomes False if it was True at
the beginning and that the all the embedded code in this loop is used. It
will therefor not repeat itself again.
Loop
Next J
End Sub

Charlie wrote:
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.

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

[quoted text clipped - 17 lines]

JJD



--
Message posted via http://www.officekb.com