Proecting Sheet Marco Question

fedas18

Board Regular
Joined
Jan 21, 2010
Messages
81
I have a spreadsheet that I am going to lock with only a few selected cells to be able to be edited. ON the same spreadsheet I have macro bottons. However when I protect the sheet, my macros do not work.

Is there a way around this?

Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Sub Whatever()
ActiveSheet.Unprotect Password:="Password1"

~~~~~~The rest of your Code~~~~~~

ActiveSheet.Protect Password:="Password1", DrawingObjects:=True, _
Contents:=True, Scenarios:=True

End Sub
 
Upvote 0
No. Sorry.
Just change "Password1" to whatever your password is that you are using. Do it in both places; the 'unprotect' and the 'protect'. (leave the quotes"" though)
Then it will unlock the sheet with your password, complete your macro, then lock it back up again.
 
Upvote 0
Thanks for the explaination!

If I wanted to have certain cells that were editable, I don't have to do that through a macro right?
 
Upvote 0
By default all cells are locked.

To unlock/lock certain cells when a worksheet is protected.

Select all cells: Ctrl + A

Format cells: Ctrl + 1 >> protection tab

Check or uncheck the Locked check box.

For your situation, highlight the cells you want to unprotect and follow the steps above.
 
Upvote 0
Hi,

I'm sorry to bother you again but I am still having trouble getting this to work.

Sub Macro12()
'
' Macro12 Macro
'
ActiveSheet.Unprotect Password:="password"
Sheets("Deficit Debt Service").Select
Range("M6").Select
Range("M6").GoalSeek Goal:=0, ChangingCell:=Range("F4")
Sheets("Executive Summary").Select
Range("A1").Select
ActiveSheet.Protect Password:="password", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub


the password on the locked sheets are all "password"

any idea what I am doing wrong?
 
Upvote 0
Thanks for the link. That is a great source.

I used the below macro which worked:

Sub Macro12()
'
' Macro12 Macro
'
ActiveSheet.Unprotect Password:="password"
Sheets("Deficit Debt Service").Select
ActiveSheet.Unprotect Password:="password"
Sheets("Deficit Debt Service").Select
Range("M6").Select
Range("M6").GoalSeek Goal:=0, ChangingCell:=Range("F4")
Sheets("Executive Summary").Select
Range("A1").Select
ActiveSheet.Protect Password:="password"
Sheets("Deficit Debt Service").Select
ActiveSheet.Unprotect Password:="password"
End Sub


THANKS FOR ALL YOUR HELP! I would not have been able to do this without you.

Thanks!
 
Upvote 0
You are selecting to different sheets in your macro.
The Command is to unprotect the active sheet.
So you will have to select the sheet then unprotect it. run your code then protect it afterwards.

So if you are not on the sheet 'Deficit Debt Service' when you start your macro, you are unprotecting the wrong sheet. Then you switch over to 'Executive Summary' and you do not unprotect that one.

Try this: (I THINK it will work)

Sub Macro12()
'
' Macro12 Macro
'
'Select the sheet first then unlock it
'
Sheets("Deficit Debt Service").Select
ActiveSheet.Unprotect Password:="password"
Range("M6").Select
Range("M6").GoalSeek Goal:=0, ChangingCell:=Range("F4")
ActiveSheet.Protect Password:="password", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
'
'Protect that sheet then select the next one
'unprotect it and move on
'
Sheets("Executive Summary").Select
ActiveSheet.Unprotect Password:="password"
Range("A1").Select
ActiveSheet.Protect Password:="password", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub

Let me know if it works for you.......
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top