View Single Post
  #4   Report Post  
George Nicholson
 
Posts: n/a
Default

This is a bit of heresy.

Use responsibly, or don't use at all.

For cust = 1 to 10000
If cust.TestValue1 = False Then GoTo NextCustomer
If cust.TestValue2 = True Then GoTo NextCustomer
......
If cust.TestValue10 = 3 Or DayOfWeek = "Jaborwocky" Then GoTo
NextCustomer

' Code to process any x's that got this far
................
NextCustomer:
Next cust

Using Labels for "jump-to"s is generally very frowned upon these days
outside of Error Handling, because it leads to sloppy practices and
spaghetti code. No argument from me. However, I personally make this one
exception frequently, as a substitute for the "GoTo Next" statement that
doesn't exist (but should). I limit it's use to when I have umpteen
evaluations to apply to an item before it "qualifies" for further action.
Yes, the code could be structured differently but I find this *much* easier
to develop, debug, read & maintain. New test? just add a line, no need to
rebuild endlessly nested If statements. The "jump" is confined to the end
of the Loop, so no harm done in my mind since it as "self contained" as the
built-in "Exit For".

HTH,
--
George Nicholson

Remove 'Junk' from return address.


"littlegreenmen1"
<littlegreenmen1.1qbsyd_1118264706.1975@excelfor um-nospam.com wrote in
message news:littlegreenmen1.1qbsyd_1118264706.1975@excelf orum-nospam.com...

I have a For/Next Loop setup, but in the middle of it I need an If/Then
Statement. My For/Next Loop scans a list of Dates and then transfers
them to an Outlook Calender. However, I dont need it to transfer
anything from before the day I run the macro. I tried inserting the
following code:

If olDate < Date Then
Next x
End If

When I use this I get a Next without For error. Is there a way to use
Next inside an If/Then conditional if the For resides outside the
If/Then? Thank you very much for any and all help.


--
littlegreenmen1
------------------------------------------------------------------------
littlegreenmen1's Profile:
http://www.excelforum.com/member.php...o&userid=23978
View this thread: http://www.excelforum.com/showthread...hreadid=377526