View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default remembering the same filtering criteria

Hi Gary,
This is exactly what I need,but I dont know how I can I do that?Any
help to go through that? Thanks
Baha


You can't use an array as Criteria; it has to be a string.

You can store a criteria in a cell (say A1) and pull it into your code
like this...

With Range("$A$2:$A$11")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=Range("A1").Value
End With

Here's a routine that takes a single criteria stored in A1 and sets
autofilter...

Sub Set_AutoFilter()
With ActiveSheet
If .AutoFilterMode Then .AutoFilterMode = False
With .Range("$A$2:$A$11")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=Range("A1").Value
End With '.Range("$A$2:$A$11")
End With 'ActiveSheet
End Sub

...where you'll need to change the range ref if not using A1 to store
the user criteria.

I tried doing a custom criteria but it didn't work as per the
recommended syntax. I even tried playing back the macro recorder code
(same as recommended syntax) and it didn't work either. Go figure!!!
Hopefully someone who actually uses both criteria in code will chime
in!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion