PDA

View Full Version : Excel - Sorting In A Protected Worksheet


Ausatco
21st Sep 2004, 00:59
I've written an Excel spreadsheet that contains a macro to sort a range of cells. Everything works as intended - so far so good.

I want to protect my intellectual property and I can do that by Protecting the worksheet. However you can't do the sort unless the worksheet is unprotected. That's easy IF YOU DON'T USE A PASSWORD. You can unprotect the sheet first thing in the macro, sort it, then re-protect it last thing.

Protection without a password is basically useless - all it does is inhibit inadvertent alteration of formulas. Anyone can defeat it from the menu with Tools|Protection|Unprotect - in fact that is what my current macro does prior to sorting, then restores protection in a similar way afterwards. Once Protection is off, of course, anyone can access the whole design of the spreadsheet and rip you off!

What I want to do is have a password-protected worksheet that allows sorting of a range without removing the protection first.

When you apply protection one of the check-boxes is Allow users of this worksheet to Sort. I've checked that, but it doesn't solve my problem - the macro won't run and the debugger reports that protected cells are the problem.

I'm missing something somewhere, can't find it in my searches of both Help and MS Knowledgebase, so if anyone has the answer I'd sure appreciate it.

Cheers

AA

Avtrician
22nd Sep 2004, 09:37
No answer for you on this, but i seem to have seen this same question on the work network. ;) ;)

Parapunter
22nd Sep 2004, 10:04
Congrats on spotting yet another shortcomig in excel. The more you use it, the more you bump up against things it won't do.

The obvious answer is write a vb script to allow you to protect & enable sorting, but easier said than done I'm afraid.

Agent86
22nd Sep 2004, 12:07
AA.

You need to add the command

ActiveSheet.Unprotect "xxxx"

at the start of your sorting macro

and the command

ActiveSheet.Protect "xxxx"

at the end. xxx is the password for the sheet protection.

Then to stop people from seeing your password you need to protect the VB code.

In Excel 2000 this is done from the VB editor. Rt click on the Modules folder and select VBAProject Properties On the Protection tab tick the "Lock project for viewing" and enter/re-enter a password.

XP may be slightly different.

Let me know if this helps

MAx

Ausatco
23rd Sep 2004, 06:44
Agent86,

You are a saint:D :D :D

Thank you very much:ok:

Parapunter, the problem is not so much what Excel cannot do, it is more that I don't know how to make it do it.:confused:


AA

Agent86
23rd Sep 2004, 06:46
AA


That was a different TV program :D

Any time

MAx

mazzy1026
23rd Sep 2004, 11:52
As an analyst I use excel quite a bit - and god dam it can even make the tea for you in the morning, but you need to know how !