Link to home
Start Free TrialLog in
Avatar of filtrationproducts
filtrationproductsFlag for United States of America

asked on

Protect/Unprotect active excel worksheet in VBA

I have an excel file that has a macro that deletes and creates columns. I recently had to protect all the cells that contain formulas because end users were accidentally overwriting them.

Now my problem is the Macro will not delete the columns because they contain protected cells.

I would like to run a command at the beginning of the macro and at the end of the macro that will unprotect the worksheet then run the normal operations, then at the end of the macro I would like it to protect the worksheet again.

I found the code to protect a specific worksheet name;

Sheet1.Unprotect Password:="Secret"
Sheet1.Protect Password:="Secret"

but my macro will be ran on a number of different worksheet tabs and I don't want to have to createa a different macro for each. Is there a way to call out the ACTIVE worksheet only when the macro is ran?

Thanks!
Dan
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial