PDA

View Full Version : Probably simple VBA issue



percy4
05-05-2009, 03:18 AM
Hi all,

I've got a problem with below code. Autofitler works fine but not the built in sort function. my sheet has no protected cells so I wonder why it dosen't work.

Please help

Best regards
Per

Sub testavsortera()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect Password:="test", userinterfaceonly:=True, AllowSorting:=True
ws.EnableAutoFilter = True
'ws.EnableSelection = xlNoRestrictions
ws.Protect
Next ws
End Sub

Bob Phillips
05-05-2009, 04:01 AM
I think I have mentioned this before that the AllowSorting option seems to just enqable or disable the Sort button, it doesn't actually allow you to sort the data (real genius that thought up that combination!).

You need to unprotect it in VBA, sort it, then protect it again.

percy4
05-05-2009, 06:09 AM
I think I have mentioned this before that the AllowSorting option seems to just enqable or disable the Sort button, it doesn't actually allow you to sort the data (real genius that thought up that combination!).

You need to unprotect it in VBA, sort it, then protect it again.

My cells are only hidden not protected but I still can't get it to work.

Per

Bob Phillips
05-05-2009, 08:56 AM
My cells are only hidden not protected





ws.Protect Password:="test", userinterfaceonly:=True, AllowSorting:=True


Those two statements seem contradictory to me.

percy4
05-05-2009, 09:56 AM
Those two statements seem contradictory to me.

Hmm thats right. But the settings for the cells are not locked. I've unchecked that box (in cell properties).

Bob Phillips
05-05-2009, 04:39 PM
Doesn't matter, the sheet is protected. My previous comment stands.