Macros - Filters

P

Pinda

I have this bit of code that I recorded as a macro,edited
it slightly and then assigned it to a button:-

Sub AleBak()
'
' AleBak Macro
' Macro recorded 30/09/2003 by Bhupinder Rayat
'

'
Sheets("LDP Template").Select
ActiveSheet.AutoFilterMode = False
Range("A7").AutoFilter Field:=7, Criteria1:="Alex
Baker"
End Sub


The code works fine, but falls down when I password
protect the worksheets. It has a problem with the line...

ActiveSheet.AutoFilterMode = False

The error message is, 'Unable to set the AutoFilter mode
property of the worksheet class.'

Can anyone tell me why this is?

Thanks in advance.

Pinda.
 
J

J.E. McGimpsey

You need to set the EnableAutoFilter property to True and protect
using userInterfaceOnly:

With Sheets("LDP Templates")
.EnableAutoFilter = True
.Protect Password:="pword", _
contents:=True, _
userInterfaceOnly:=True
End With

Unfortunately, those properties need to be set on a per session
basis, so you'll probably want to include them in a Workbook_Open
event macro (stored in the ThisWorkbook code module)
 

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

Top