How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Brandon M. Your Own Question

Brandon M.
Brandon M., Computer Support Specialist
Category: Microsoft Office
Satisfied Customers: 6971
Experience:  10+ Years Mac Support as contractor and currently an System Administrator for law firm
Type Your Microsoft Office Question Here...
Brandon M. is online now
A new question is answered every 9 seconds

I hope you can help. I need a macro to protect

Resolved Question:

I hope you can help. I need a macro to protect multiple worksheets in a workbook (not all but only ones specified) can I do this with the worksheet names? Your help would be greatly appreciated. Please note one of the sheets I do not want protected contains a pivot table, I need the filter to be able to be used.

Submitted: 1 year ago.
Category: Microsoft Office
Expert:  Brandon M. replied 1 year ago.

BeBoo :

Hello and welcome to JustAnswer! My name is XXXXX XXXXX I would be glad to assist you with your issue today. Please note that I am in eastern time (UTC -5:00) and am generally online between the hours of 10 AM and 4 PM and some evenings between 7 PM and 11 PM.

BeBoo :

It is possible to single out the sheets. The code you provided already works, correct? But it protects each sheet, right?

BeBoo :

If so, you just need a simple if statement or a switch case. Switch cases are easier to use and understand. Let me know when you are around and I can explain.

Customer:

Hi Brandon,

Customer:

Is it possible for you to amend my script to allow for individual sheets

BeBoo :

Yes, does the existing script work?

Customer:

yes

BeBoo :

Great. Just after the For Each line, you'll want to do something like this:

BeBoo :

Select Case wsheet.Name
Case "Sheet1"
wsheet.Protect Password:="123"
Case "Sheet2"
wsheet.Protect Password:="456"
End Select

BeBoo :

All you need to do is add more Case statements for the sheet names

Customer:

the password XXXXX be the same right?

Customer:

just one more thing if I can, if I want to unlock sheets at start of script and lock at end what is the start of the script to lock if I put Const mypass As String = into script it does not work

Customer:

ie after this but before end sub

Customer:

End With
Sheets("Debtors Historical Data").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors EV Raw Data").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors C Flow").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors Summ").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors Details").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors Input").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select

BeBoo :

Sorry, I am not sure I am following - You want to unlock all of the sheets using the mypass string, right?

Customer:

I would like to do so without requesting password XXXXX lock without requesting password XXXXX only as part of another macro script, I have to refresh a pivot table and if cells are locked it will not let me use the filter

Customer:

This is the script with running macro to unprotect and protect

Customer:

Application.Run "'Debtors Final.xlsm'!UnProtectSheets"
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Debtors Input").Select
Range("A1").Select
Sheets("Debtors EV Raw Data").Select
Range("A1").Select
Sheets("Debtors Historical Data").Select
Range("A1").Select
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Sheets("Debtors Input").Select
Range("O3").Select
ActiveCell.SpecialCells(xlCellTypeSameValidation).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Range("P3").Select
ActiveCell.SpecialCells(xlCellTypeSameValidation).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Range("O3").Select
ActiveCell.FormulaR1C1 = _
"=IF(IFERROR(VLOOKUP(RC[-8],'Debtors Historical Data'!R2C1:R10003C21,'Debtors Historical Data'!RC15),""No Ref"")=1,IFERROR(VLOOKUP(RC[-8],'Debtors Historical Data'!R2C1:R10003C21,15),""No Ref""),R10921C15)"
Range("O3").Select
Selection.AutoFill Destination:=Range("O3:O10003")
Range("O3:O10003").Select
Range("P3").Select
ActiveCell.FormulaR1C1 = _
"=IF(IFERROR(VLOOKUP(RC[-9],'Debtors Historical Data'!R2C1:R10003C21,'Debtors Historical Data'!RC16),""No Ref"")=1,IFERROR(VLOOKUP(RC[-9],'Debtors Historical Data'!R2C1:R10003C21,16),""No Ref""),R10214C16)"
Range("P3").Select
Selection.AutoFill Destination:=Range("P3:P10003")
Range("P3:P10003").Select
Range("Q3").Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP(RC[-10],'Debtors Historical Data'!R[-1]C1:R[10000]C20,17),"""")"
Range("Q3").Select
Selection.AutoFill Destination:=Range("Q3:Q10921")
Range("Q3:Q10921").Select
Range("O3:Q10921").Select
Selection.Copy
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("O3:O10003").Select
Application.CutCopyMode = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=$Bw$3:$Bw$920"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Range("P3:P10003").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=$Bv$3:$Bv$214"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Sheets("Debtors Historical Data").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors EV Raw Data").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors C Flow").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors Summ").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors Details").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("Debtors Input").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Range("A1").Select
Application.Run "'Debtors Final.xlsm'!ProtectSheets"
End Sub

Customer:

it stops here

Customer:


ActiveCell.SpecialCells(xlCellTypeSameValidation).Select

BeBoo :

Without having the actual workbook, you would just need to do the same thing with the For loop except do wsheet.Unprotect Password:="123"

Brandon M., Computer Support Specialist
Category: Microsoft Office
Satisfied Customers: 6971
Experience: 10+ Years Mac Support as contractor and currently an System Administrator for law firm
Brandon M. and 8 other Microsoft Office Specialists are ready to help you

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
< Last | Next >
  • My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed. One Happy Customer New York
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
 
 
 

Meet The Experts:

 
 
 
  • jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
< Last | Next >
  • http://ww2.justanswer.com/uploads/JS/jstinehelfer/2012-6-6_215146_Pictureofme1.64x64.png jstinehelfer's Avatar

    jstinehelfer

    Information Systems Manager

    Satisfied Customers:

    36
    A+ Comptia Certified computer repair
  • http://ww2.justanswer.com/uploads/JA/JasonJames122/2011-12-16_135647_jasonjamesheadshotweb.64x64.jpg JasonJames122's Avatar

    JasonJames122

    Computer Enthusiast

    Satisfied Customers:

    0
    I manage all information systems (network of Windows PC's and servers with Microsoft Office products) for a small business
  • http://ww2.justanswer.com/uploads/JE/jessmagz/2012-6-6_18129_jm.64x64.jpg Jess M.'s Avatar

    Jess M.

    Computer Support Specialist

    Satisfied Customers:

    301
    Computer Software Specialist for more than 10 years
  • http://ww2.justanswer.com/uploads/CH/chutz747/2011-11-6_14231_me.64x64.jpg The-PC-Guy's Avatar

    The-PC-Guy

    Computer Manager

    Satisfied Customers:

    274
    20 years experience providing remote computer support
  • http://ww2.justanswer.com/uploads/SP/spherrod/2012-6-6_174244_1000852.64x64.JPG Steve Herrod's Avatar

    Steve Herrod

    Computer Support Specialist

    Satisfied Customers:

    125
    Trained in Microsoft Office from 2000 through to latest version 2010.
  • http://ww2.justanswer.com/uploads/SE/Seashore2011/2011-12-6_33418_111205223015.64x64.jpg Chris L.'s Avatar

    Chris L.

    Support Specialist

    Satisfied Customers:

    124
    Certified Expert with over 10 years experience.
  • http://ww2.justanswer.com/uploads/KR/krkljatorm/2012-6-24_153417_ITMiro.64x64.jpg IT Miro's Avatar

    IT Miro

    Computer Scientist

    Satisfied Customers:

    97
    Bachelor's Degree in Information Technology, Microsoft Certified Professional