I am trying to create macros to toggle between different views for an excel worksheet but keep getting "Run-time error '1004": Unable to set the Hidden property of the Range class. My goal is to use the same set of code but change the ranges for the hidden columns and unhidden columns. Below is the basic structure I am trying to use.
I have tried many different iterations of the formula with no luck. Any assistance would be great! Thanks.
Code:
Sub Hidden_Column_View()
'Unprotect Worksheet
ActiveSheet.Unprotect
'Unhide Columns
Columns("A:HY").EntireColumn.Hidden = False
Range("A:J,M:O,Q:AL,AX:DB,EB:EG,FC:FF,FS:GH,GP:GU,HH:HY").EntireColumn.Hidden = Not Range("K:L,AM:AW,DC:EA,EH:FB,FG:FR,GI:GO,GV:HG,HZ:ID").EntireColumn.Hidden
'Protect Worksheet
ActiveSheet.Protect , AllowFiltering:=True
End Sub
I have tried many different iterations of the formula with no luck. Any assistance would be great! Thanks.