How do you use "except" in a for next loop

H

hotherps

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
 
T

Trevor Shuttleworth

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
 
T

Trevor Shuttleworth

Post the full routine; I had to make it up and I've obviously guessed wrong
 
H

hotherps

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
 
B

BrianB

'-----------------------------------------------
For j = 100 To 144
If j <> 119 Then ........

'------------------------------------------------

Don't need Step 1 which is the default
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top