Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do you use "except" in a for next loop

I keep getting a "next without for" error

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default 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/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default 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/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
change increasment in a "for" loop Jared Excel Discussion (Misc queries) 6 October 6th 06 07:21 AM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 06:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"