Add Error Message To Sheet Password
Results 1 to 4 of 4

Thread: Add Error Message To Sheet Password

  1. #1
    New Member
    Join Date
    Nov 2018
    Posts
    44
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Add Error Message To Sheet Password

    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.

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,661
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Add Error Message To Sheet Password

    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
    Regards Dante Amor

  3. #3
    New Member
    Join Date
    Nov 2018
    Posts
    44
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Add Error Message To Sheet Password

    Perfect! I knew I'd be missing something so simple but just couldn't see it.

    Thank you

  4. #4
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,661
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Add Error Message To Sheet Password

    Quote Originally Posted by Pavertheway View Post
    Perfect! I knew I'd be missing something so simple but just couldn't see it.

    Thank you

    I'm glad to help you. Thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •