Modify code to only lock certain excel sheets

How do I modify the following code in excel to only lock certain sheets, for example I want to only lock sheets "RFQ" and "QA_CLAUSES" in my workbook.

Sub ToggleProtection()
    Dim oWs As Worksheet
    Dim sPw

    sPw = Application.InputBox("What's The Secret Sauce?", "Enter Password Skillit")
    If sPw = False Or sPw = "" Then
        MsgBox "Nothing Entered"
        Exit Sub
    End If

    For Each oWs In ThisWorkbook.Worksheets
        If oWs.ProtectContents Then
            oWs.Unprotect sPw
        Else: oWs.Protect sPw
        End If

    Next oWs
End Sub
LUIS FREUNDAsked:
Who is Participating?
 
Martin LissConnect With a Mentor Older than dirtCommented:
For Each oWs In ThisWorkbook.Worksheets
    Select Case oWs.name
        Case "RFQ", "QA_Cluases" ' Is that spelled right?
            oWs.Protect sPw         
        Case Else
            oWs.Unprotect sPw
    End Select
Next oWs

Open in new window

0
 
Martin LissOlder than dirtCommented:
For Each oWs In ThisWorkbook.Worksheets
    Select Case oWs.name
        Case "A workbook name", "Another name'
            ' do something            
        Case Else
            'do something with the rest of the worksheets
    End Select
Next oWs

Open in new window

0
 
LUIS FREUNDAuthor Commented:
So under workbook name and another name I enter the "RFQ" and QA_CLUSES"...the sheet names?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Martin LissOlder than dirtCommented:
Yes, in line 3 you would add the sheets names in quotes for which you want to do something special, and one of them might be "RFQ". The default action defined by code that you place between lines 5 and 7 will be done to all the the other worksheets.
0
 
Martin LissOlder than dirtCommented:
I'd update my posted code but I don't know the names of the special worksheets and what you want to do to them.
0
 
Anna bellConnect With a Mentor Commented:
The default action defined by code that you place between lines 5 and 7 will be done to all the the other worksheets.
0
 
LUIS FREUNDAuthor Commented:
Basically wanted worksheet "RFQ" and "QA_Cluases" locked while the rest us not affected.  I'm new to VBA...
0
 
LUIS FREUNDAuthor Commented:
Thank you very much!
0
 
Martin LissOlder than dirtCommented:
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.