![]() |
How do you use "except" in a for next loop
I have some code that loops through some records:
For j = 100 To 144 Step 1 num = "" If Len(Trim(arr(j))) = 0 Then num = j arr(num) = "PK" Exit For What if I want to make an exception, what if 119 does not exist, fo example, how do you exclude specific numbers from this statement. Thank -- Message posted from http://www.ExcelForum.com |
How do you use "except" in a for next loop
Try something like this:
Dim arr(100 To 144) For j = 100 To 144 Step 1 num = "" Select Case j Case Is = 119 'do nothing ' MsgBox "119" Case Else If Len(Trim(arr(j))) = 0 Then num = j arr(num) = "PK" Exit For End If End Select Next 'j Regards Trevor "hotherps " wrote in message ... I have some code that loops through some records: For j = 100 To 144 Step 1 num = "" If Len(Trim(arr(j))) = 0 Then num = j arr(num) = "PK" Exit For What if I want to make an exception, what if 119 does not exist, for example, how do you exclude specific numbers from this statement. Thanks --- Message posted from http://www.ExcelForum.com/ |
How do you use "except" in a for next loop
|
How do you use "except" in a for next loop
Post the full routine; I had to make it up and I've obviously guessed wrong
"hotherps " wrote in message ... I keep getting a "next without for" error? --- Message posted from http://www.ExcelForum.com/ |
How do you use "except" in a for next loop
Thanks Trevor that worked great.
Now a really dumb question, what if I have to exclude more than on value? (I probably should have mentioned that the first time, sorry. let's say 135,137,139 for exampl -- Message posted from http://www.ExcelForum.com |
How do you use "except" in a for next loop
Case Is = 119,135,137,139 'do nothing
Regards Trevor "hotherps " wrote in message ... Thanks Trevor that worked great. Now a really dumb question, what if I have to exclude more than one value? (I probably should have mentioned that the first time, sorry. let's say 135,137,139 for example --- Message posted from http://www.ExcelForum.com/ |
How do you use "except" in a for next loop
'-----------------------------------------------
For j = 100 To 144 If j < 119 Then ........ '------------------------------------------------ Don't need Step 1 which is the default -- Message posted from http://www.ExcelForum.com |
All times are GMT +1. The time now is 02:56 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com