Protecting all worksheets except one

  • I have a code that protects all worksheets within the open workbook, and it works very well. I've not included a worksheet that I don't want to protect. The worksheet is called "LogDetails". Is it possible to insert some code into the following to exclude protecting this specific tab?


    Code
    Sub Protect()
    '
    ' Protect Macro
    ' Protects all worksheets. Protects without a password.
    '
    For i = 1 To Sheets.Count
    Sheets(i).Protect
    Next i
    End Sub
  • Try this

    Code
    Sub Protect()
        '
        ' Protect Macro
        ' Protects all worksheets. Protects without a password.
        '
        For i = 1 To Sheets.Count
            If Sheets(i).Name <> "LogDetails" Then Sheets(i).Protect
        Next i
    End Sub

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • You're welcome

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.


    How to use code tags


    Just highlight all of the code and press the <> in the post menu above button to add the code tags.


    Thanks.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!