VBA Select Case-

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
335
Can you set set different values to 2 different variables using the select case statment? An example of what I was trying is below. It runs but it seems that the Max value is not picked up.




Range1 = ActiveCell.Offset(0, 4).Value
Range2 = Worksheets("Results").Range("V1").Value
Range3 = Range1 & Range2

Select Case Range3
Case "StableCash Equivalents"
Min = 0 And Max = 1
Case "IncomeCash Equivalents"
Min = 0 And Max = 0.2
Case "Income with GrowthCash Equivalents"
Min = 0 And Max = 0.2
Case "BalancedCash Equivalents"
Min = 0 And Max = 0.2
Case "Growth with IncomeCash Equivalents"
Min = 0 And Max = 0.2
Case "GrowthCash Equivalents"
Min = 0 And Max = 0.2
Case "OtherCash Equivalents"
Min = 0 And Max = 0.2

End Select
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
[Edit]didn't read everything...

You should be able to just put them on seperate lines, or if you MUST have them on one line, use a :.

i.e.

Min=0
Max=1

-or-

Min=0:Max=1
 
Upvote 0
Lose the And.:)

Either put the 2 assignments on different lines, or seperate with a semi colon.
Code:
Min = 0
Max = 0.2
Code:
Min = 0:Max = 0.2
By the way you can use multiple values for the case.
Code:
Select Case Range3
Case "StableCash Equivalents"

    Min = 0: Max = 1
    
Case "IncomeCash Equivalents", "Income with GrowthCash Equivalents", _
     "BalancedCash Equivalents", "Growth with IncomeCash Equivalents", _
     "GrowthCash Equivalents", "OtherCash Equivalents"
     
    Min = 0: Max = 0.2
    
End Select
 
Upvote 0

Forum statistics

Threads
1,217,676
Messages
6,137,935
Members
450,099
Latest member
Pushbutton

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top