VBA Select Case-

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
334
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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

BJungheim

Well-known Member
Joined
Jul 24, 2004
Messages
914
[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
 

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
334
Yes, Min and Max are both Variables.

I get a line--- Error if I put the ()

Thanks for the tip.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,136,878
Messages
5,678,301
Members
419,753
Latest member
Sallylwy

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
Top