Macros - filters

P

Pinda

I have this bit of code that I recorded and then edited
slightly: -

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

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


I have various macros linked to buttons like this. The
macros work fine, the above macros will display everything
relating to Alex Baker, as it will pick up Alex Baker from
the filter list. However, sometimes the macros fall down
and I get the following message:-

"Autofilter method of Range class failed".

When i debug, it has a problem with this line: -

Selection.AutoFilter Field:=7, Criteria1:="Alex Baker"

The macro failing sometimes places the filter in A1, or
gets rid of it altogether.

Can anyone explain why this might happen?

Hope ive explain well enough.

Thanks in advance.

Pinda
 
D

Debra Dalgleish

You criteria area should have a blank heading cell, and the following
formula in the cell below: =AND(A2>TODAY()-15,A2<TODAY()-7)

if the dates start in cell A2.

When you run the Advanced Filter, select the blank cell and the cell
with the formula, as the criteria range.
 
D

Debra Dalgleish

Instead of Selection.AutoFilter, specify the cell where the AutoFilter
should start, e.g.:

Range("A4").AutoFilter Field:=7, Criteria1:="Alex Baker"
 

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

Similar Threads


Top