Add Error Message To Sheet Password

Pavertheway

New Member
Joined
Nov 5, 2018
Messages
47
Hi,

I currently use the following code to lock a sheet in a Workbook:

Code:
mysheet = "Sheet1"If ActiveSheet.Name = mysheet Then
ActiveSheet.Visible = False
    Response = InputBox("Enter password to view sheet")
        If Response = "Sheet1" Then
            Sheets(mysheet).Visible = True
            Application.EnableEvents = False
            Sheets(mysheet).Select
            Application.EnableEvents = True
            End If
End If
Sheets(mysheet).Visible = True

When the password is entered incorrectly, I would like to add a simple message stating "Password entered incorrectly" - how would I do this?

Thanks as always.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try this

Code:
Sub test()
  Dim mysheet As String, Response As Variant
  mysheet = "Sheet1"
  If ActiveSheet.Name = mysheet Then
    ActiveSheet.Visible = False
    Response = InputBox("Enter password to view sheet")
    If Response = "Sheet1" Then
      Sheets(mysheet).Visible = True
      Application.EnableEvents = False
      Sheets(mysheet).Select
      Application.EnableEvents = True
    Else
      MsgBox "Password entered incorrectly"
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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