Select Case with Enum

confusion123

Active Member
Joined
Jul 27, 2014
Messages
400
I have the following select case statement:

Code:
Dim a As String

Select Case Range("MyCar").Value

    Case "Porsche"

        a = "Expensive"

    Case "Fiat"

        a= "Moderate"

    Case "Mini"

        a = "Cheap"

End Select

I would like to incorporate Enums, so

Code:
Public Enum Style

    Porsche = 1
    Fiat = 2
    Mini = 3

End Enum

Dim a As String

Select Case Range("MyCar").Value

    Case Style.Porsche

        a = "Expensive"

    Case Style.Fiat

        a= "Moderate"

    Case Style.Mini

        a = "Cheap"

End Select

However, this does not produce the desired result.

If I put "Porsche" into the Range "MyCar" and run the code, it does not recognise Style.Porsche as Porsche. Instead Style.Porsche = 1.

How can I make it work?

Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
As I said here when you asked this before, you can't do this.
 
Upvote 0

Forum statistics

Threads
1,203,171
Messages
6,053,871
Members
444,691
Latest member
Breizze1313

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