Case Statement - names represent cases

KyleG

Well-known Member
Joined
Jun 12, 2004
Messages
623
Not sure if im doing this right as this is my first attempt at a case statement. Every other time have planned on doing one have found another way around the problem.

Heres what i have.

Private Sub Workbook_Open()
MY_PASS = InputBox("Please enter the password", "PASSWORD PROTECTED")
Select Case MY_PASS
Case April: Worksheets("DELI").Select
Case ValP: Worksheets("Bulkfoods").Select
Case Nathan: Worksheets("Grocery").Select
End Select
End Sub

It doesnt work though.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Kyle

Input Box Function returns a string. Therefore you need to have your Case values in quotation marks.
Code:
Case "April": Worksheets("DELI").Select

HTH

Regards
 
Upvote 0
Try this:

Code:
Private Sub Workbook_Open()
Dim MY_PASS
MY_PASS = InputBox("Please enter the password", "PASSWORD PROTECTED")
Select Case MY_PASS
    Case "April"
        Worksheets("DELI").Select
    Case "ValP"
        Worksheets("Bulkfoods").Select
    Case "Nathan"
        Worksheets("Grocery").Select
End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,739
Messages
6,057,081
Members
444,904
Latest member
SelamT

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