VBA code to Hide/Unhide a Worksheet in a Workbook

DominicanExcel

New Member
Joined
May 8, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello, I would like the VBA code to Hide/Unhide a Worksheet in a Workbook with a Formula.

I'm attaching a sample workbook where I would like the "Data" tab to be hidden/unhidden with password "test" upon clicking on cell C6 link on the "Content" tab.

Thanks
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
If you are doing this to deter the casual user and are not concerned with it being cryptographically secure then something like this is a simple way
(note that this example uses the double-click event)

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Const PW = "Test"
    Dim Ans As String

    If Target.Address = "$C$6" Then
        Ans = InputBox("Password")
        If Ans = PW Then
            With ThisWorkbook.Worksheets("Data")
                If .Visible = xlSheetVisible Then
                    .Visible = xlSheetVeryHidden
                Else
                    .Visible = xlSheetVisible
                End If
            End With
        Else
            MsgBox "Incorrect Password"
        End If
    End If
End Sub


If you are trying for cryptographically secure, then things quickly get a lot more complicated.
 
Upvote 0

Forum statistics

Threads
1,215,157
Messages
6,123,341
Members
449,097
Latest member
thnirmitha

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