Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]() 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 |
#2
![]() |
|||
|
|||
![]() It will be interesting to see others' solutions, but I think, instead of what you've got, I'd do: If oldate=Date 'make calender code' end if next x -- MrShorty ------------------------------------------------------------------------ MrShorty's Profile: http://www.excelforum.com/member.php...o&userid=22181 View this thread: http://www.excelforum.com/showthread...hreadid=377526 |
#3
![]() |
|||
|
|||
![]()
No, the code syntax you describe will not work. Try something
like For X = whatever to whatever If olDate = Date Then ' your code here End If Next X You could also forego using a For Next loop and use a Do While/Until Loop, which allows you to change an index whenever you need to. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "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 |
#4
![]() |
|||
|
|||
![]()
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 |
#5
![]() |
|||
|
|||
![]()
George,
I agree. A few short jumps don't hurt no one no how. Ask an assembler programmer. I, when feeling very civic-minded and responsible, use something like: For cust = 1 to 10000 Do If cust.TestValue1 = False Then Exit Do If cust.TestValue2 = True Then Exit Do ...... If cust.TestValue10 = 3 Or DayOfWeek = "Jaborwocky" Then Exit DO ' Code to process any x's that got this far ................ Loop While "pigs" = "fly" Next cust -- Earl Kiosterud mvpearl omitthisword at verizon period net ------------------------------------------- "George Nicholson" wrote in message ... 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 |
#6
![]() |
|||
|
|||
![]()
*Very* interesting. I'll keep that structure in mind.
However, I'm not 100% sure about the civic-mindedness aspect: I can easily see it blowing the mental fuse of a neophyte coming across it during mainenance. :-) -- George Nicholson Remove 'Junk' from return address. "Earl Kiosterud" wrote in message ... George, I agree. A few short jumps don't hurt no one no how. Ask an assembler programmer. I, when feeling very civic-minded and responsible, use something like: For cust = 1 to 10000 Do If cust.TestValue1 = False Then Exit Do If cust.TestValue2 = True Then Exit Do ...... If cust.TestValue10 = 3 Or DayOfWeek = "Jaborwocky" Then Exit DO ' Code to process any x's that got this far ................ Loop While "pigs" = "fly" Next cust -- Earl Kiosterud mvpearl omitthisword at verizon period net ------------------------------------------- "George Nicholson" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
loop trough e-mail address list to send task lists with outlook | Excel Discussion (Misc queries) | |||
Loop through email address list to send e-mails | Excel Discussion (Misc queries) | |||
Password Loop question. | Excel Discussion (Misc queries) | |||
Printe Autofilter Criterias in a Loop | Excel Discussion (Misc queries) | |||
Please help with loop | Excel Discussion (Misc queries) |