Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Select case syntax for continuous range values?


I know you can use Select case statements to cover a range of integer
values, such as:

Case 100 To 500
Case 501 to 650
etc

However, I'm not clear on how to work with non-integer values to ensure that
every possible value is covered, while ensuring no overlap in categories.
With an IF statement I might use:

If x 100 and x <=500
elseif x 500 and x <=650

which would properly assign a value of 500.4395 to the second condition

Is there a way to do this with select case? Or is my best option to try to
use more decimals than the data might need, e.g.

Case 100 To 500
Case 500.000001 to 650

Thank you,
Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Select case syntax for continuous range values?

You can step thru the code below that I gave and you'll see that the case
where x = 500.4395 the Select Case Statement will work. Change the x
variable to whatever you like and you'll see.

Sub Select_Case()

Dim x As Double

x = 500.4395

Select Case x
Case Is <= 100
MsgBox "x is Less than 100"
Case 100 To 500
MsgBox "x is Between 100-500"
Case 500 To 650
MsgBox "x is Between 500-650"
Case 650 To 1000
MsgBox "x is Between 650-1000"
Case Else
MsgBox "x is Greater than 1000"
End Select

End Sub

Excel VBA evaluates each Case to see if it is true before moving to the next
Case. If the Case is true your code under the Case is executed, if False the
next Case is evaluated.

Hope this helps! If so, click "YES" below.
--
Cheers,
Ryan


"ker_01" wrote:


I know you can use Select case statements to cover a range of integer
values, such as:

Case 100 To 500
Case 501 to 650
etc

However, I'm not clear on how to work with non-integer values to ensure that
every possible value is covered, while ensuring no overlap in categories.
With an IF statement I might use:

If x 100 and x <=500
elseif x 500 and x <=650

which would properly assign a value of 500.4395 to the second condition

Is there a way to do this with select case? Or is my best option to try to
use more decimals than the data might need, e.g.

Case 100 To 500
Case 500.000001 to 650

Thank you,
Keith

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
Newbie: Problem with 'Select Case' testing syntax Thomas Toth Excel Programming 9 September 11th 07 04:34 PM
Select Case syntax Alan Beban Excel Programming 14 July 15th 07 11:51 PM
Select Case for Active Worksheet syntax. mikeburg[_43_] Excel Programming 2 December 2nd 05 12:26 AM
Syntax for Select Case Susan Hayes Excel Programming 4 November 30th 05 10:49 AM
Select Case syntax Susan Hayes Excel Programming 2 December 4th 04 10:42 PM


All times are GMT +1. The time now is 11:15 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"