![]() |
Jump to the next count in a FOR Loop
Hi,
I have For I = 1 to 67 If ..... then 'Here I would like to go to the next Count in I and skip the execution of code till -- Next I -- End if '..... ' Some code 'Some code '.... '... Next I Please tell me what I should put inside the If statement so that I could accomplish the above. I cannot use -- Exit For -- as I dont want to stop the executon of loop abruptly. Thanks a lot, Hari India |
Jump to the next count in a FOR Loop
Hi Hari
One way: For I = 1 to 67 If ..... then 'Here I would like to go to the next Count in I and skip the execution of code till -- Next I -- Else '..... ' Some code 'Some code '.... '... End if Next I -- Best Regards Leo Heuser Followup to newsgroup only please. "Hari Prasadh" skrev i en meddelelse ... Hi, I have For I = 1 to 67 If ..... then 'Here I would like to go to the next Count in I and skip the execution of code till -- Next I -- End if '..... ' Some code 'Some code '.... '... Next I Please tell me what I should put inside the If statement so that I could accomplish the above. I cannot use -- Exit For -- as I dont want to stop the executon of loop abruptly. Thanks a lot, Hari India |
Jump to the next count in a FOR Loop
For i = 1 to 67
if not condition then ' some code ' some code end if Next -- Regards, Tom Ogilvy "Hari Prasadh" wrote in message ... Hi, I have For I = 1 to 67 If ..... then 'Here I would like to go to the next Count in I and skip the execution of code till -- Next I -- End if '..... ' Some code 'Some code '.... '... Next I Please tell me what I should put inside the If statement so that I could accomplish the above. I cannot use -- Exit For -- as I dont want to stop the executon of loop abruptly. Thanks a lot, Hari India |
Jump to the next count in a FOR Loop
Hi Leo,
Im sorry, I should have mentioned this in my original post. Actually what u suggested Im already using. It's just that I wanted to know about other ways of dealing with it. Especially what happens if I have many instances of -- 'Here I would like to go to the next Count in I and skip the execution of code till ...-- within a single very big For Loop. Managing such a If else End If, becomes a little difficult. (Especially in the case when conditions are mutually exclusive) Thanks a lot, Hari India |
Jump to the next count in a FOR Loop
Hari, Maybe something like: For i = 1 To Alot If Something Then GoTo SkipOut 'code here If SomethingElse Then GoTo SkipOut 'or code here If Not StillSomethingElse Then GoTo SkipOut 'other code here SkipOut: Next i HTH, Bernie MS Excel MVP "Hari Prasadh" wrote in message ... Hi Leo, Im sorry, I should have mentioned this in my original post. Actually what u suggested Im already using. It's just that I wanted to know about other ways of dealing with it. Especially what happens if I have many instances of -- 'Here I would like to go to the next Count in I and skip the execution of code till ...-- within a single very big For Loop. Managing such a If else End If, becomes a little difficult. (Especially in the case when conditions are mutually exclusive) Thanks a lot, Hari India |
Jump to the next count in a FOR Loop
How about
Select Case 'your test' Case 'value1' : 'do nothing Case 'value2' : ' do nothing 'etc. Case Else: myMacro End Select where myMacro includes your code. You can easily add extra conditions. -- HTH RP (remove nothere from the email address if mailing direct) "Hari Prasadh" wrote in message ... Hi Leo, Im sorry, I should have mentioned this in my original post. Actually what u suggested Im already using. It's just that I wanted to know about other ways of dealing with it. Especially what happens if I have many instances of -- 'Here I would like to go to the next Count in I and skip the execution of code till ...-- within a single very big For Loop. Managing such a If else End If, becomes a little difficult. (Especially in the case when conditions are mutually exclusive) Thanks a lot, Hari India |
Jump to the next count in a FOR Loop
Hi Bernie,
Thnx a lot. Would use it for my purpose. Your method of Skipout reminds me of On Error go to ...method, which I learned recently. Thanks a lot, Hari India "Bernie Deitrick" <deitbe @ consumer dot org wrote in message ... Hari, Maybe something like: For i = 1 To Alot If Something Then GoTo SkipOut 'code here If SomethingElse Then GoTo SkipOut 'or code here If Not StillSomethingElse Then GoTo SkipOut 'other code here SkipOut: Next i HTH, Bernie MS Excel MVP |
Jump to the next count in a FOR Loop
Generally, if you examine the logic of your task, your code can fit into the
IF ... Then or Case construct. Using GoTo makes your code much more difficult to read - go back and look at some complex code you haven't looked at in a month or two and see if you can easily understand your logic. This it the advantage of a) using structured programming b) documenting your code. c) coding in blocks and using subroutines and functions There may be cases where a goto or exit is necessary, but you should employ them minimally and not as standard practice. Perhaps your response it that the code is only for you, but you seem to post a lot of it up here and want people to understand it. -- Regards, Tom Ogilvy "Hari Prasadh" wrote in message ... Hi Bernie, Thnx a lot. Would use it for my purpose. Your method of Skipout reminds me of On Error go to ...method, which I learned recently. Thanks a lot, Hari India "Bernie Deitrick" <deitbe @ consumer dot org wrote in message ... Hari, Maybe something like: For i = 1 To Alot If Something Then GoTo SkipOut 'code here If SomethingElse Then GoTo SkipOut 'or code here If Not StillSomethingElse Then GoTo SkipOut 'other code here SkipOut: Next i HTH, Bernie MS Excel MVP |
Jump to the next count in a FOR Loop
Hi Tom,
You are right about GoTo being difficult interpretations and flow wise. I just wanted to be aware of the contents of Tool-Box as much as possible. Sometimes when Im stuck in middle of something (compilation or run-time problem) then using a bad solution (Go To) for temporary period of time seems to be a way out of dead-end. What I do is to add a comment and when I get time I post the question on NG . For example, the problem I had yesterday with Match and Iserror function... I was trying somehow to solve the problem, but both the approaches were blanking out. So for that moment I would have been happier even if i could have got Iserror working, so that it would have got me working temporarily. Oh.. yes ..In the morning when I saw your solution, I chose variant data type rather than Exit Sub!! Thanks a lot, Hari India "Tom Ogilvy" wrote in message ... Generally, if you examine the logic of your task, your code can fit into the IF ... Then or Case construct. Using GoTo makes your code much more difficult to read - go back and look at some complex code you haven't looked at in a month or two and see if you can easily understand your logic. This it the advantage of a) using structured programming b) documenting your code. c) coding in blocks and using subroutines and functions There may be cases where a goto or exit is necessary, but you should employ them minimally and not as standard practice. Perhaps your response it that the code is only for you, but you seem to post a lot of it up here and want people to understand it. -- Regards, Tom Ogilvy "Hari Prasadh" wrote in message ... Hi Bernie, Thnx a lot. Would use it for my purpose. Your method of Skipout reminds me of On Error go to ...method, which I learned recently. Thanks a lot, Hari India "Bernie Deitrick" <deitbe @ consumer dot org wrote in message ... Hari, Maybe something like: For i = 1 To Alot If Something Then GoTo SkipOut 'code here If SomethingElse Then GoTo SkipOut 'or code here If Not StillSomethingElse Then GoTo SkipOut 'other code here SkipOut: Next i HTH, Bernie MS Excel MVP |
Jump to the next count in a FOR Loop
Got to endorse Tom's wise words. IMO it is a weakness of VBA that we need
goto's for error handling, a throwback to older Basics I guess. I once worked on a electoral roll application written in Cobol, a version of Cobol that allowed alterable gotos. Can you imagine the nightmare of trying to debug that. Bob "Tom Ogilvy" wrote in message ... Generally, if you examine the logic of your task, your code can fit into the IF ... Then or Case construct. Using GoTo makes your code much more difficult to read - go back and look at some complex code you haven't looked at in a month or two and see if you can easily understand your logic. This it the advantage of a) using structured programming b) documenting your code. c) coding in blocks and using subroutines and functions There may be cases where a goto or exit is necessary, but you should employ them minimally and not as standard practice. Perhaps your response it that the code is only for you, but you seem to post a lot of it up here and want people to understand it. -- Regards, Tom Ogilvy "Hari Prasadh" wrote in message ... Hi Bernie, Thnx a lot. Would use it for my purpose. Your method of Skipout reminds me of On Error go to ...method, which I learned recently. Thanks a lot, Hari India "Bernie Deitrick" <deitbe @ consumer dot org wrote in message ... Hari, Maybe something like: For i = 1 To Alot If Something Then GoTo SkipOut 'code here If SomethingElse Then GoTo SkipOut 'or code here If Not StillSomethingElse Then GoTo SkipOut 'other code here SkipOut: Next i HTH, Bernie MS Excel MVP |
All times are GMT +1. The time now is 05:39 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com