Macros - filters

  • Thread starter Thread starter Pinda
  • Start date Start date
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
 
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.
 
Instead of Selection.AutoFilter, specify the cell where the AutoFilter
should start, e.g.:

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