Use VBA to delete conditional formatting from a protected sheet

Jaye Cavallo

New Member
Joined
Mar 10, 2022
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
I am attempting to use VBA to delete conditional formatting on a protected worksheet. When I run the simple macro below, I receive a 400 error. However, if I unprotect the worksheet, remove the lines of code for unprotect/protect, the macro works without error and removes all the conditional formatting for the worksheet. Any suggestions are appreciated.

Sub RemoveConditionalFormatting()

Dim WS As Worksheet
Set WS = ActiveSheet

ActiveSheet.Unprotect Password:="hadley4000", UserInterfaceOnly:=True

WS.Range("A2:Z3569").Cells.FormatConditions.Delete

ActiveSheet.Protect Password:="hadley4000", UserInterfaceOnly:=True

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Welcome to the Board!

Error 400 could indicate that there are issues with the Excel file (could be corrupted or infected) itself or your Excel installation.

Have a look at these two articles here:
 
Upvote 0
The unprotect line should be
VBA Code:
ActiveSheet.Unprotect Password:="hadley4000"
 
Upvote 0
Solution
Thanks for the replay regarding error 400. I am going through the process now. Will let you know if I can resolve.
 
Upvote 0
Thank you for the suggestion to correct my code, Fluff, for protecting/unprotecting a worksheet.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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