Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Select Case Not Returning Correct String

My Select Case is not returning the correct string. For example, when L =
39, my code always returns "18'' T12 (F18T12HO)" and not "36'' T12
(F36T12HO)", why?

I think VBA is just looking at the first part of Case and not the part after
the AND. I'm not sure how to force it to look at the part after the AND.

Sub cmbEstimate_Click()

Select Case L = Lwidth - Sockets

Case L < 18
MsgBox "This cabinet is too small to use Fluorescents.", vbCritical
Exit Sub

Case 18 < L And L <= 24
cboLamps1 = "18'' T12 (F18T12HO)"

Case 24 < L And L <= 30
cboLamps1 = "24'' T12 (F24T12HO)"

Case 30 < L And L <= 36
cboLamps1 = "30'' T12 (F30T12HO)"

Case 36 < L And L <= 42
cboLamps1 = "36'' T12 (F36T12HO)"

End select

End sub

Thanks in Advance,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Select Case Not Returning Correct String

Select Case L = Lwidth - Sockets

is evaluating

L = Lwidth - Sockets

which is either true or false. Use this:

L = Lwidth - Sockets
Select Case L

Then your cases need to deal with the value of L but not include L.

You also don't need two parts, just put them in order. Let's restructu

Select Case True
Case L <= 18

Case L <= 24

Case L <= 30

'etc.

End Select

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"RyanH" wrote in message
...
My Select Case is not returning the correct string. For example, when L =
39, my code always returns "18'' T12 (F18T12HO)" and not "36'' T12
(F36T12HO)", why?

I think VBA is just looking at the first part of Case and not the part
after
the AND. I'm not sure how to force it to look at the part after the AND.

Sub cmbEstimate_Click()

Select Case L = Lwidth - Sockets

Case L < 18
MsgBox "This cabinet is too small to use Fluorescents.", vbCritical
Exit Sub

Case 18 < L And L <= 24
cboLamps1 = "18'' T12 (F18T12HO)"

Case 24 < L And L <= 30
cboLamps1 = "24'' T12 (F24T12HO)"

Case 30 < L And L <= 36
cboLamps1 = "30'' T12 (F30T12HO)"

Case 36 < L And L <= 42
cboLamps1 = "36'' T12 (F36T12HO)"

End select

End sub

Thanks in Advance,
Ryan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Select Case Not Returning Correct String

On Fri, 15 Feb 2008 06:27:02 -0800, RyanH
wrote:

My Select Case is not returning the correct string. For example, when L =
39, my code always returns "18'' T12 (F18T12HO)" and not "36'' T12
(F36T12HO)", why?

I think VBA is just looking at the first part of Case and not the part after
the AND. I'm not sure how to force it to look at the part after the AND.

Sub cmbEstimate_Click()

Select Case L = Lwidth - Sockets

Case L < 18
MsgBox "This cabinet is too small to use Fluorescents.", vbCritical
Exit Sub

Case 18 < L And L <= 24
cboLamps1 = "18'' T12 (F18T12HO)"

Case 24 < L And L <= 30
cboLamps1 = "24'' T12 (F24T12HO)"

Case 30 < L And L <= 36
cboLamps1 = "30'' T12 (F30T12HO)"

Case 36 < L And L <= 42
cboLamps1 = "36'' T12 (F36T12HO)"

End select

End sub

Thanks in Advance,
Ryan


How are you setting the value of L? (Your code does not do that).

There is nothing in the code you posted indicating that you have ever set L
equal to something.

Your Select Case statement will return TRUE or FALSE. True will always
evaluate to less than 18, so your first Case statement will always be the one
that is executed.

You need to read HELP for Operator Precedence and also for the Select Case
function.

Perhaps something like (not-tested):
l = lwidth - sockets
Select Case L
Case < 18
...
case 18 to 24
...
case 25 to 30
...

--ron
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 without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Help with If,then statement Returning Value (or Select Case) [email protected] Excel Programming 4 December 20th 06 05:28 PM
MAX Function not returning correct value Phil Excel Worksheet Functions 4 April 28th 06 10:14 PM
UDF not returning correct information [email protected] Excel Programming 1 July 14th 05 12:04 AM


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