Macro Clear Button - Reset Protect with Format Rows Option

JenMcG

New Member
Joined
Dec 2, 2016
Messages
46
Hello,

I've created a macro to clear the unprotested cells in a worksheet. In order for this to work I've built into the macro to unprotect the sheet (at the beginning) and then re-protect it (at the end). This serves my purpose except it does not reset the options to format rows. How can I add this?

Sub Clearcells1()
ActiveSheet.Unprotect Password:="1300church"
Range("C2:D2", "C3:D3").ClearContents
Range("B8", "F27").ClearContents
Range("B32", "F34").ClearContents
Range("F39", "F42").ClearContents
Range("E42").ClearContents
Range("E46").ClearContents
Range("E51").ClearContents
Range("F52", "F53").ClearContents
Range("E54").ClearContents
Range("E58").ClearContents
Range("F64").ClearContents
Range("F68").ClearContents
ActiveSheet.Protect Password:="1300church"
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I recorded this macro with all the protection methods I wanted on my sheet. You can do the same

VBA Code:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True
 
Upvote 0
I recorded this macro with all the protection methods I wanted on my sheet. You can do the same

VBA Code:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True
Thank you- where should this be inserted in the macro?
 
Upvote 0
It should replace the line with Activesheet.protect. You, of course will have to add your password at end. I encourage you to record a macro where you set the parameters you need for the protected sheet.

VBA Code:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFormattingColumns:=True, Password:="1300church"
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,692
Members
449,117
Latest member
Aaagu

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