text box for password

The Idea Dude

Well-known Member
Joined
Aug 15, 2002
Messages
591
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I require some code that will (when called) pop up a text box for the user to enter in a password, if password is correct then it will take user to Sheet1, if incorrect then msgbox.

Any help greatly appreciated.

Thanks :)
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
At a basic level:
Code:
Sub checkPW()
Dim myPass as String, userPW as String
myPass = "some_silly_password"
 
userPW = InputBox("Enter your password.", "Password")
If userPW = myPass Then
    Sheets("Sheet1").Activate
Else
    MsgBox "Sorry, you entered an incorrect password."
End If
End Sub
If Sheet1 is hidden, you'd need to unhide it before activating it, of course.
 
Upvote 0
1) Create Userform and place 1 x TextBox and 1 x CommandButton
2) paste the code onto the form module
Code:
Private Sub UserForm_Initialize()
    Me.TextBox1.PasswordChar = "*"
End Sub
 
Private Sub CommandButton1_Click()
    If Me.TextBox1.Value <> "PassWord" Then
        MsgBox "Invalid entry"
        Me.TextBox1.Value = ""
    Else
        Unload Me
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,040
Messages
6,128,454
Members
449,455
Latest member
jesski

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