Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select Case, Less and Greater than?


I am trying to get my code to take a value and work out which actions to
do based on where the number is situated in the ranges.

a = Range("B3").Select

Select Case a
Case Is 0 < 9
'do stuff
MsgBox ("less than 10")
Case Is 10 < 999
'do stuff
MsgBox ("less than 100")
Case Is 1000 < 40000
'do stuff
MsgBox ("less than 1000")
End Select

Only problem is, the code doesnt work, and neither does IF statements.
What am I doing wrong?!

Thank you


--
Sami82
------------------------------------------------------------------------
Sami82's Profile: http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=475351

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select Case, Less and Greater than?

You criteria is basically a filter, so you stop as soon as you satisfy a
condition. Therefore you don't need to specify a lower bound:

Sub testCase()
i = 100

Select Case i
Case Is < 10
MsgBox "< 10"
Case Is < 100
MsgBox "=10 and < 100"
Case Is < 1000
MsgBox " = 100 and < 1000"
Case Is < 10000
MsgBox " = 1000 and < 10000"
Case Else
MsgBox " = 10000"
End Select
End Sub

as an example.

--
Regards,
Tom Ogilvy

"Sami82" wrote in
message ...

I am trying to get my code to take a value and work out which actions to
do based on where the number is situated in the ranges.

a = Range("B3").Select

Select Case a
Case Is 0 < 9
'do stuff
MsgBox ("less than 10")
Case Is 10 < 999
'do stuff
MsgBox ("less than 100")
Case Is 1000 < 40000
'do stuff
MsgBox ("less than 1000")
End Select

Only problem is, the code doesnt work, and neither does IF statements.
What am I doing wrong?!

Thank you


--
Sami82
------------------------------------------------------------------------
Sami82's Profile:

http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=475351



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select Case, Less and Greater than?

Just an added thought.
That would work for integers

Sub selectgreaterthan()
Select Case 9.5
Case 1 To 9
MsgBox "1"
Case 10 To 999
MsgBox "10"
Case Else
MsgBox "Error"
End Select
End Sub

gives error.

--
Regards,
Tom Ogilvy

"Don Guillett" wrote in message
...
the HELP file index for case would give a good example
Sub selectgreaterthan()
Select Case Range("b3")
Case 1 To 9
MsgBox "1"
Case 10 To 999
MsgBox "10"
'etc
Case Else
End Select
End Sub

--
Don Guillett
SalesAid Software

"Sami82" wrote in
message ...

I am trying to get my code to take a value and work out which actions to
do based on where the number is situated in the ranges.

a = Range("B3").Select

Select Case a
Case Is 0 < 9
'do stuff
MsgBox ("less than 10")
Case Is 10 < 999
'do stuff
MsgBox ("less than 100")
Case Is 1000 < 40000
'do stuff
MsgBox ("less than 1000")
End Select

Only problem is, the code doesnt work, and neither does IF statements.
What am I doing wrong?!

Thank you


--
Sami82
------------------------------------------------------------------------
Sami82's Profile:

http://www.excelforum.com/member.php...o&userid=27111
View this thread:

http://www.excelforum.com/showthread...hreadid=475351





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Select Case, Less and Greater than?

Good morning Tom,

OK 1 to 10 or <10 as you suggested.

--
Don Guillett
SalesAid Software

"Tom Ogilvy" wrote in message
...
Just an added thought.
That would work for integers

Sub selectgreaterthan()
Select Case 9.5
Case 1 To 9
MsgBox "1"
Case 10 To 999
MsgBox "10"
Case Else
MsgBox "Error"
End Select
End Sub

gives error.

--
Regards,
Tom Ogilvy

"Don Guillett" wrote in message
...
the HELP file index for case would give a good example
Sub selectgreaterthan()
Select Case Range("b3")
Case 1 To 9
MsgBox "1"
Case 10 To 999
MsgBox "10"
'etc
Case Else
End Select
End Sub

--
Don Guillett
SalesAid Software

"Sami82" wrote in
message ...

I am trying to get my code to take a value and work out which actions

to
do based on where the number is situated in the ranges.

a = Range("B3").Select

Select Case a
Case Is 0 < 9
'do stuff
MsgBox ("less than 10")
Case Is 10 < 999
'do stuff
MsgBox ("less than 100")
Case Is 1000 < 40000
'do stuff
MsgBox ("less than 1000")
End Select

Only problem is, the code doesnt work, and neither does IF statements.
What am I doing wrong?!

Thank you


--
Sami82


------------------------------------------------------------------------
Sami82's Profile:

http://www.excelforum.com/member.php...o&userid=27111
View this thread:

http://www.excelforum.com/showthread...hreadid=475351









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Select Case, Less and Greater than?

Sami82
Are you declaring your variables ?
Dim a As ????

NickHK

"Sami82" wrote in
message ...

I am trying to get my code to take a value and work out which actions to
do based on where the number is situated in the ranges.

a = Range("B3").Select

Select Case a
Case Is 0 < 9
'do stuff
MsgBox ("less than 10")
Case Is 10 < 999
'do stuff
MsgBox ("less than 100")
Case Is 1000 < 40000
'do stuff
MsgBox ("less than 1000")
End Select

Only problem is, the code doesnt work, and neither does IF statements.
What am I doing wrong?!

Thank you


--
Sami82
------------------------------------------------------------------------
Sami82's Profile:

http://www.excelforum.com/member.php...o&userid=27111
View this thread: http://www.excelforum.com/showthread...hreadid=475351



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 301
Default Select Case, Less and Greater than?

a = Range("B3").Select will give variable a the value of TRUE or FALSE, not
the value of cell B3!
Try
a=Range("B3").Value

Bob Umlas
Excel MVP

"NickHK" wrote in message
...
Sami82
Are you declaring your variables ?
Dim a As ????

NickHK

"Sami82" wrote in
message ...

I am trying to get my code to take a value and work out which actions to
do based on where the number is situated in the ranges.

a = Range("B3").Select

Select Case a
Case Is 0 < 9
'do stuff
MsgBox ("less than 10")
Case Is 10 < 999
'do stuff
MsgBox ("less than 100")
Case Is 1000 < 40000
'do stuff
MsgBox ("less than 1000")
End Select

Only problem is, the code doesnt work, and neither does IF statements.
What am I doing wrong?!

Thank you


--
Sami82
------------------------------------------------------------------------
Sami82's Profile:

http://www.excelforum.com/member.php...o&userid=27111
View this thread:
http://www.excelforum.com/showthread...hreadid=475351





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
Select Case jlclyde Excel Discussion (Misc queries) 5 January 6th 09 09:05 PM
Select case Hein Excel Discussion (Misc queries) 2 October 22nd 08 07:06 AM
Case Select NoodNutt Excel Worksheet Functions 7 September 21st 08 02:10 AM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Case Select Kelly Excel Programming 6 March 16th 05 01:29 PM


All times are GMT +1. The time now is 03:59 PM.

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

About Us

"It's about Microsoft Excel"