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
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,010
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
46,010
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
46,010
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
46,010
Office Version
  1. 365
Platform
  1. Windows
Glad you sorted it & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,108,502
Messages
5,523,295
Members
409,508
Latest member
Afc

This Week's Hot Topics

Top