VBA to unhide a very hidden tab and then hide current tab

sryan429

New Member
Joined
Jul 1, 2016
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a code that I use to launch an input box, when the correct password is entered it unlocks a specific tab, that was previously VeryHidden. I'd like to modify it so it also hides the current sheet when the answer is correct. When I try to modify, I end up hiding the active sheet whether the password is correct or incorrect. Thank you in advance!

Example, within Sheet1 I click a box, type in a password. If password is correct it unhides Sheet 2 and hides Sheet 1. If it is incorrect, Sheet 1 remains visible and Sheet 2 stays very hidden.


Code:
Sub UnlockSheet2()
With Sheets("Sheet2")
    .Visible = IIf(InputBox("Enter the correct password") = "PASSWORD", xlSheetVisible, xlSheetVeryHidden)
    If .Visible = xlSheetVeryHidden Then MsgBox "Sorry wrong answer, try again!"
End With
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
Code:
Sub UnlockSheet2()
   If InputBox("Enter the correct password") = "PASSWORD" Then
      Sheets("Sheet2").Visible = True
      Sheets("Sheet1").Visible = xlSheetVeryHidden
   Else
      MsgBox "Sorry wrong answer, try again!"
   End If
End Sub
 
Upvote 0
Brilliant, thank you Fluff!!!! This was exactly what I was looking for
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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