Jaye Cavallo
New Member
- Joined
- Mar 10, 2022
- Messages
- 45
- Office Version
- 2016
- Platform
- 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
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