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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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 bellCommented:
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
Martin LissOlder 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.