Hide / Unhide Columns in Password Protected w/s

M

monir

Hello;

I'm trying to protect/hide the formulas on a w/s by protecting the w/s so
that I may not accidentally delete or overwrite them.
It works fine with the exception that the Hide & Unhide column no longer
available either via Format::Column::Hide and Unhide or by a macro.

The macro to hide / unhide columns produces:
Run-time error '1004':
"Unable to set the Hidden property of the Range class"
and in the macro code:
......Range("J1:K1").Select
....>Selection.EntireColumn.Hidden = True is highlighted

Is there a workaround this difficulty; namely protecting the w/s formulas
and still be able to Hide / Unhide columns ??

Thank you kindly.
 
R

Rick Rothstein \(MVP - VB\)

In its simplest form, you could do toggle the visibility using this macro...

Sub ToggleColumnVisibility()
Me.Unprotect
With Range("J:K").EntireColumn
.Hidden = Not .Hidden
End With
Me.Protect
End Sub

However, the Protect method has a lot of optional arguments that allow you to customize the level of protection, so you should check it out in the help files if your protection needs to be any more than the basic default settings.

Rick
 
M

monir

Rick;
Perfect! Thank you.
(Obviously in your code, one must replace Me keyword with ActiveSheet in a
standard macro.)

Another way is suggested by schielrn and jonmo1. In the existing standard
macro, add:
Sub Hide_UnHide ()
ActiveSheet.Unprotect "Password"
'... Code to hide / unhide
ActiveSheet.Protect "Password"
End Sub

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top