View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Next For looping in a If

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