macro and protected sheets

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,256
Office Version
  1. 2016
Hi, I have a worksheet which I protect with these settings.


  • Select unlocked cells
  • Use auto filter
  • Use pivot table and pivot chart

Once set, all works well, however....

I have a macro I use which expands or retracts the row heights in my table. When I run this I use this code.

Code:
Sub EXPAND()'
' EXPAND Macro
'


'
[COLOR=#ff0000]ActiveSheet.Unprotect Password:="password"[/COLOR]
    Rows("19:19").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Rows.AutoFit
    ActiveWindow.SmallScroll Down:=-15
    Range("A1").Select
[COLOR=#ff0000]    ActiveSheet.Protect Password:="password"[/COLOR]
End Sub
Sub RETRACT()
'
' RETRACT Macro
'


'
[COLOR=#ff0000]ActiveSheet.Unprotect Password:="password"[/COLOR]
    Rows("19:19").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.RowHeight = 16
    Range("J15").Select
    ActiveWindow.SmallScroll Down:=-16
    Range("A1").Select
[COLOR=#ff0000]    ActiveSheet.Protect Password:="password"[/COLOR]
End Sub


I have to activate and deactivate the password for the macro to work.

Heres the problem....

When I do this, the protect sheet selections are all erased...

These no longer apply...


  • Select unlocked cells
  • Use auto filter
  • Use pivot table and pivot chart

Is there a way of retaining these settings either within or outside of the macr?

Thanks.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Record a macro of you unprotecting & then re-protecting the sheet.
That should show you what parameters you need for to use when setting protection
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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