Run Macro only if data entered in cell is correct

Manus99

Board Regular
Joined
May 5, 2004
Messages
104
Hello,

I have a workbook with 3 spreadsheets with the following labels. The first is the "opening" sheet, the second is "Private", the third is "Public"

The opening sheet is nothing but 2 buttons. You can enter either public or private. I have macros for each button. If you click the private button you see all tabs. If you click the public button you only see the "public" worksheet. What I want to do is have my private macro run, only if a correct password is entered into a cell B11.

Is there a way to have it so if you click private button with the wrong password, or nothing in cell B11 then you get an error message.... but if you enter the correct password then the macro runs?

Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Why not use an InputBox?
Code:
rspn = InputBox ("Enter Password")
If rspn <> "password" Then Exit Sub
lenze
 
Upvote 0
That sounds like a good approach to my issue... however I am unfamiliar with input boxes. Where can I find that? Thanks.
 
Upvote 0
I assume you have a macro for your "Private" button on the "opening" sheet. Just make the lines I posted the first 2 lines of code. Change "password" to whatever you desire.

See the VBA help file for detailed info.

lenze
 
Upvote 0
Lenze that is perfect! Thank you so much for your help... and I learned something completely new that is easy.

Thanks again!
 
Upvote 0
You might want to include a message for them. Something like
Code:
rspn = InputBox ("Enter Password")
If rspn <> "password" Then 
      MsgBox "Wrong password" 
      Exit Sub
End If

lenze
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

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