Protected Sheet won't sort

  • Thread starter Thread starter Chuck
  • Start date Start date
C

Chuck

When activating the protection of a sheet, I've allowed
for users to sort. I've created a macro button that
highlights contents of the sheet (including protected
cells)

The macro stops and during debug I can see that it stops
at the sort command. After trying it manually an error
comes up to tell me that the cell I'm trying to access is
protected and I need to unprotect cells.

I'm not changing the contents of the cell, why am I
getting this error.

How can I allow for sorting of protected cells as well as
unprotected cells.
 
You can't sort protected sheets, you have to unprotect in your code first.
Here is some sample code I use for our timesheets.

ActiveSheet.Unprotect
Range(Cells(23, 1), Cells(69, 12)).Select
Selection.Sort Key1:=Range("A23"), Order1:=xlAscending,
Key2:=Range("H23" _
), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=
_
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2 _
:=xlSortNormal
temp = ActiveSheet.Range("A23:A69")
size = WorksheetFunction.CountA(temp)
Cells(23 + size, 1).Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

Paul D
 

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

Back
Top