User For for Hidden Sheet Revealed by Password

nau2002

Board Regular
Joined
Dec 19, 2016
Messages
97
Hello,

I have a simple user form that is to unhide a deeply hidden sheet via password. Unfortunately, the hidden sheet is revealed whether the user enters the correct or an incorrect password. Can someone help me adjust my code, please?

Private Sub CommandButton1_Click()
If TextBox1 = "test" Then
Sheet2.Visible = True
Else
MsgBox "Password Entered is Incorrect"

End If
Unload Me
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
The sheet should only become visible if TextBox =test
 
Upvote 0
Sorry, not sure I understand your response. Are you saying it should work as I have it written? I should note that it also reveals the hidden sheet if someone just hits the cancel button on the user form.
 
Upvote 0
The code you posted should work, but from you last post I think you have other problems.
Can you please post all the code from the Userform.
When posting code please use code tags, the # icon in the reply window.
 
Upvote 0
Hopefully I did this right. It's not letting me paste directly from VB so I put it in Word first and then copied here. Thanks for looking!

Code:
[COLOR=#574123][FONT="Tahoma"][FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]

[COLOR=#574123][FONT="Tahoma"]Private SubCommandButton1_Click()[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]If TextBox1= "test" Then[/FONT][/COLOR]

[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]Sheet25.Visible= True[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]Else[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]MsgBox"Password entered is incorrect"[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]Unload Me[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]End If[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]End Sub[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]Private SubCommandButton2_Click()[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]Unload Me[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]End Sub[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]Private SubTextBox1_Change()[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]End Sub[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]Private SubUserForm_Click()[/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"] [/FONT][/COLOR]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[COLOR=#574123][FONT="Tahoma"]End Sub[/FONT][/COLOR]


[/FONT][/COLOR]

 
Upvote 0
If that is the only code in the userform, then sheet25 will only become visible if you enter test into Textbox1
 
Upvote 0
Just to close the loop on this. you're right Fluff, the code was working fine.

My problem was another macro triggered by a change event that I had to clean up.
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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