password protect button

jlocker

New Member
Joined
Feb 25, 2019
Messages
3
Hi,

I'd like to require a password before the button can be "pushed". I'm not great with macros, so I'm really just looking for what I need to add to my current code. This is the macro I have assigned to the button:

Sub sHideASheet()

Sheets("Sheets2").Visible = True
Sheets("Sheets3").Visible = True

End Sub

I've tried a few of the suggestions from previous posts, but none seem to work for me. I don't know if it makes a difference, but the sheets being unhidden are very hidden. Any help is appreciated!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try this macro. Replace the text in red to a password of your choosing.
Code:
Sub sHideASheet()
    Dim PW As String, response As String
    PW = "[COLOR="#FF0000"]Mypassword[/COLOR]"
    response = InputBox("Please enter the password.")
    If response = "" Then Exit Sub
    If response <> PW Then
        MsgBox ("Invalid password.  Please try again.")
        Exit Sub
    End If
    Sheets("Sheets2").Visible = True
    Sheets("Sheets3").Visible = True
End Sub
 
Upvote 0
Thank you very much for the help. There a password prompt now when I push the button, but upon entering the password, I get an error message that says, "Subscript out of range." The debugger highlights this line - Sheets("Sheets2").Visible True.

Any suggestions?
 
Upvote 0
Please disregard my first response. It was a typo in my original code that was causing the error. The code should have read: Sheets("Sheet2").Visible = True

When I corrected the tab names, it worked perfectly.

THANK YOU AGAIN!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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