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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
The sheet should only become visible if TextBox =test
 

nau2002

Board Regular
Joined
Dec 19, 2016
Messages
97
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
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.
 

nau2002

Board Regular
Joined
Dec 19, 2016
Messages
97

ADVERTISEMENT

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]

 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
If that is the only code in the userform, then sheet25 will only become visible if you enter test into Textbox1
 

nau2002

Board Regular
Joined
Dec 19, 2016
Messages
97
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,598
Messages
5,832,646
Members
430,150
Latest member
amitk1

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
Top