#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Select Case

Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Select Case

You must put the smaller value on the left of the "To" keyword and the
larger value on the right...

Select Case Delta1ToSP
Case -0.05 To -0.02 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -1 To -0.10001
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

--
Rick (MVP - Excel)



"David" wrote in message
...
Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
--
David


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 563
Default Select Case

The statement: Case -0.02 To -0.05
needs to be coded as: Case -0.05 To -0.02
since -0.05 is smaller than -0.2
Don't be too hard on yourself - it is Sunday!
best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme


"David" wrote in message
...
Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
--
David


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Select Case

Reverse the arguments. The negative number has twisted your head (as they
often do mine) and the Case ...To... needs small magnitude first: -.02 is
LARGER in magnitude than -0.05.

Case -0.05 To -0.02
will catch the value.



"David" wrote:

Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
--
David

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Select Case


Thank you all. When I read through help, I don't think this was mentioned.

"Don't be too hard on yourself - it is Sunday!" Space, the final frontier,
lol.

--
David


"Rick Rothstein" wrote:

You must put the smaller value on the left of the "To" keyword and the
larger value on the right...

Select Case Delta1ToSP
Case -0.05 To -0.02 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -1 To -0.10001
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

--
Rick (MVP - Excel)



"David" wrote in message
...
Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
--
David


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Select Case

I wouldn't use both end points.

I'd just check to see what it was less than (or less than or equal to):

Select Case Delta1ToSP
Case is <= -0.10 'that last 0 will disappear, but I kept it here!
Stop
Case is <= -0.05
Stop
Case is <= -0.02
Stop
Case is <= 0.05
Stop
Case is <= 0.10
Stop
Case is <= 1
Stop
Case Else
Stop
End select

The first case that matches is the one that is used.

And I don't have to worry about what happens at -0.0500000001



David wrote:

Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
--
David


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Select Case

It's mentioned in the Description for "expressionlist-n" (4th sentence) in
the table with the Part/Description heading.

--
Rick (MVP - Excel)



"David" wrote in message
...

Thank you all. When I read through help, I don't think this was mentioned.

"Don't be too hard on yourself - it is Sunday!" Space, the final frontier,
lol.

--
David


"Rick Rothstein" wrote:

You must put the smaller value on the left of the "To" keyword and the
larger value on the right...

Select Case Delta1ToSP
Case -0.05 To -0.02 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -1 To -0.10001
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

--
Rick (MVP - Excel)



"David" wrote in message
...
Hello Group,

I have a select case that is not working as I expected, Delta1ToSP =
-3.38629648094637E-02 or -.0338:

Select Case Delta1ToSP
Case -0.02 To -0.05 ' This is where I expected the stop
Stop
Case -0.050001 To -0.1
Stop
Case -0.10001 To -1
Stop
Case 0.02 To 0.05
Stop
Case 0.050001 To 0.1
Stop
Case 0.10001 To 1
Stop
Case Else
Stop
End Select

What am I missing?

Thanks,
--
David


.

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
Case not recognized in Select Case kevlarmcc Excel Programming 4 March 29th 10 07:40 PM
Select Case Ken[_4_] Excel Programming 1 January 26th 09 03:56 PM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM


All times are GMT +1. The time now is 12:04 PM.

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"