View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Stefi Stefi is offline
external usenet poster
 
Posts: 2,646
Default Aouto filter by macro

Insert this event sub into code window of Sheet2:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A1" Then Call filtFcol(Target.Value)
End Sub

Insert this sub into a normal module:
Sub filtFcol(filtval)
Worksheets("Sheet1").Select
Columns("F:F").Select
Selection.AutoFilter
If filtval = "all" Then
Selection.AutoFilter Field:=1
Else
Selection.AutoFilter Field:=1, Criteria1:=filtval
End If
End Sub

Regards,
Stefi


€žnader€ť ezt Ă*rta:

hi stefi

Description of my question is:

I have a dropdown list like:

toyota
nissan
kia
all

in "sheet2" cell "A1" and i have column F in "sheet1" contain names above.
I want to have a macro, when i choose a value from dropdown list in "sheet2"
"A1" and apply macro, Excell filters in "sheet1" column F by this value and
when i choose "all" value in dropdown list and apply this macro again, it
unhides all cells, including blanks.

kind regards,
nader

"Stefi" wrote:

The VBA equivalent of choosing All from Autofilter dropdown list is:
Selection.AutoFilter Field:=6
It must unhide all cells, including blanks. If you have other problem, give
more details!

Regards,
Stefi

€žnader€ť ezt Ă*rta:

HI Stefi
when i filter(all) by your macro it don't show blanks.
is possible it show blanks too?
it is important for me.
thanks

"Stefi" wrote:

You are welcome! Thanks for the feedback!
Stefi

€žnader€ť ezt Ă*rta:

HI Stefi

it works well.

any thanks.
nader

"Stefi" wrote:

Try this way:
Selection.AutoFilter Field:=6, _
Criteria1:="=" & Sheets("Sheet2").Range("A1").Value

Regards,
Stefi


€žnader€ť ezt Ă*rta:

hi all dears

i need your helps
I use following mocro:

Sheets("Sheet1").Select
Selection.AutoFilter Field:=6, _
Criteria1:="=" & Range("Sheet2!A1").Value

I need to filter(All) by putting a value in cell ("Sheet2!A1").

Thanks.