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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,214,424
Messages
6,119,407
Members
448,894
Latest member
spenstar

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