View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Shaggyjh Shaggyjh is offline
external usenet poster
 
Posts: 15
Default how to sort in a protected worksheet.

Sorry to hijack this thread but i am trying to do the same thing, sort a
protected sheet.
Excel 2003

I have protected the sheet allowing users to select unlocked and locked
cells, as well as the Sort tick box is ticked. Password for the time being
is (just quick and easy): a

I have the following Macro assigned to a button called Sort:

Sub Sort_Click()
Dim coltosort As Range
Set coltosort = Application.InputBox(Prompt:= _
"Select A Column", Type:=8)
ActiveSheet.Unprotect Password:="a"
ActiveSheet.UsedRange.Sort Key1:=coltosort.Cells(2), _
Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
With ActiveSheet
...Protect Password:="a"
...EnableSelection = xlNoRestrictions
End With
End Sub

When i click on the button i get a Compile Error, Syntax Error with the
options of Ok and Help. If i click Ok the debugger highlights the 1st line
and the ..Protect password line:

Sub Sort_Click() in yellow

...Protect Password:="a" in blue

Also when the macro is in the debugger both these lines are in red font:

...Protect Password:="a"
...EnableSelection = xlNoRestrictions

Sorry this is my 1st experience of the debugger!

Any help would be greatly appreciated.

"Gord Dibben" wrote:

Then you will have to provide a macro to unprotect the sheet, do the sort then
re-protect the sheet.

First, under ToolsProtectionProtect Sheet allow users to "select locked cells"

Then password protect with your choice of password.

Assign this macro to button or shortcut key. Note: no error-checking.

Sub sortit()
Dim coltosort As Range
Set coltosort = Application.InputBox(Prompt:= _
"Select A Column", Type:=8)
ActiveSheet.Unprotect Password:="justme"
ActiveSheet.UsedRange.Sort Key1:=coltosort.Cells(2), _
Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
With ActiveSheet
..Protect Password:="justme"
..EnableSelection = xlNoRestrictions
End With
End Sub


Gord Dibben MS Excel MVP

On Tue, 16 Oct 2007 09:30:01 -0700, clm wrote:

that won't work as i want to send the worksheet out to a large audience. the
data needs to be protected, but want to let the audience sort the data
according to their needs. don't want them to change the data; just be able to
sort.