PDA

View Full Version : [SOLVED:] Macro removes editing options selected when re-protecting worksheet after macro runs



joshdog13
07-25-2021, 05:13 PM
I have a button that performs a macro on the "Cycle Time" sheet that hides rows without data in them in column B. The macro is written to unprotect the sheet, hide the rows, then reprotect the sheet. For some reason though the macro removes my selected editing options that I have selected when re-protecting worksheet after macro runs.

I am trying to keep the check boxes selected for Select locked cells, Select unlocked cells, Format rows, Insert rows, Delete rows, Sort, Use AutoFilter, Use Pivot Table & Pivot Chart, Edit objects, and Edit Scenarios. I have row 5 selected as my row to be able to filter and sort and Allow Edit Ranges set to allow rows 6-13 to be sorted while the sheet is locked.

Everytime the macro button is clicked and the macro runs, the only ones left checked are Select locked cells and Select unlocked cells. Any help on how to fix this is greatly appreciated!

Paul_Hossler
07-25-2021, 05:51 PM
Not sure if Button17_Click is supposed to do anything, since there's no Sheet1 in the workbook

I'd change Button46_Click a little





Sub Button46_Click()
Dim r1 As Range, r2 As Range, c As Range

Application.ScreenUpdating = False

With Sheet20
.Unprotect


.Rows.Hidden = False


Set r1 = .Range("b5")
Set r2 = .Cells(.Rows.Count, 2).End(xlUp)

For Each c In Range(r1, r2).Cells
If Len(c.Text) = 0 Then c.EntireRow.Hidden = True
Next

.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, _
AllowFormattingRows:=True, AllowInsertingRows:=True, AllowDeletingRows:=True, _
AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
End With


Application.ScreenUpdating = True




End Sub