+ Reply to Thread
Results 1 to 4 of 4

Password protect sheet - modify code

Hybrid View

  1. #1
    Registered User
    Join Date
    10-20-2010
    Location
    MD
    MS-Off Ver
    Excel 2003
    Posts
    53

    Password protect sheet - modify code

    Hello,

    I want to use the code below but I need it to function on 3 sheets not only in one.

    I tried: If Sh.Name = "Sheet1" And "Sheet2" And "Sheet3" Then, but it doesn't work, I don't think I'm doing right, if smb could help me with one.

    Thank you.


    Public PvSh As String
    Public Pwd As String
    
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Pwd = "" Then
    If Sh.Name = "Sheet1" Then
    Num = ActiveWindow.Index
    Windows(Num).Visible = False
    If Application.InputBox("Enter Password", "Password") <> "12345" Then
    MsgBox "Incorrect Password", vbCritical, "Error"
    Application.EnableEvents = False
    Sheets(PvSh).Select
    Application.EnableEvents = True
    Else
    Pwd = "12345"
    End If
    Windows(Num).Visible = True
    End If
    End If
    End Sub
    
    Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    PvSh = Sh.Name
    End Sub

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Password protect sheet - modify code

    If Sh.Name = "Sheet1" or If Sh.Name = "Sheet2" or If Sh.Name = "Sheet3" Then
    for instance
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    10-20-2010
    Location
    MD
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Password protect sheet - modify code

    Thank you. Issue solved.
    But the correct code is:

    If Sh.Name = "Sheet1" or Sh.Name = "Sheet2" or Sh.Name = "Sheet3" Then

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Password protect sheet - modify code

    yes-I apologize-I copied and pasted the first part and forgot to remove the extra Ifs

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1