Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting Data In A Protected Excel Worksheet 1

Status
Not open for further replies.

FletchUK

Programmer
Nov 6, 2001
16
0
0
GB
Does anyone know if it is possible to sort data in a protected Excel worksheet?
I have created a sheet which has a command button which when clicked runs a macro to automatically sort the data into the correct order (it's a league table.) Everything works fine until I lock the worksheet (to prevent accidental changes to the formulas etc.) and then the sort button returns a runtime error. I have tried unlocking the range but this doesn't help and I've now noticed that the sort option on the Data menu is greyed out when the sheet is protected. When the sheer is unprotected the button works fine again. Does anyone know a way around this?
Thanks,
Fletch
 
Hi
Basically you can't do the sort on a protected sheet, as I think you've realised. The basic reason is that you would be changing the sheet which would defeat the object of protecting in the first place. OK I know unlocking cells blows this logic out of the water but who ever said these things were logical??!!

To get around your problem try this
Code:
ActiveSheet.Unprotect
'SORT CODE IN HERE
ActiveSheet.Protect

Have a look at the help for protect & unprotect as there are arguments that can be passed such as password.

Happy Friday
;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
 
Hi Loomah

Many thanks for your help. The command button now functions perfectly, even when the worksheet is protected.

Fletch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top