Need some help with Autofilter VBA

AMAT

New Member
Joined
Mar 6, 2003
Messages
14
Hello,

My key strokes to record the macro are:
- Ctrl-Home
- Ctrl-F "platform"
- Alt-Downarrow "reflexion"
- Enter

The resulting VBA is:
Range("A1").Select
Cells.Find(What:="platform", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveSheet.Range("$G$1:$P$46").AutoFilter Field:=7, Criteria1:= _
"=REFLEXION", Operator:=xlOr, Criteria2:="=REFLEXION LK"


I want the VAB to do the autofilter on the column that it found the word "platform" in row 1, not on the 7th column from the left (Field:=7).

Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi,

One way would be something like this:
Code:
Sub AF()
    Dim r  As Range
    With ActiveSheet
        .AutoFilterMode = False
        With .Range("$G$1:$P$46")
            Set r = .Find(what:="platform", after:=.Range("G1"))
            .AutoFilter Field:=r.Column - .Column + 1, Criteria1:= _
                "=REFLEXION", Operator:=xlOr, Criteria2:="=REFLEXION LK"
        End With
    End With
End Sub
 
Upvote 0
Hi,

One way would be something like this:
Code:
Sub AF()
    Dim r  As Range
    With ActiveSheet
        .AutoFilterMode = False
        With .Range("$G$1:$P$46")
            Set r = .Find(what:="platform", after:=.Range("G1"))
            .AutoFilter Field:=r.Column - .Column + 1, Criteria1:= _
                "=REFLEXION", Operator:=xlOr, Criteria2:="=REFLEXION LK"
        End With
    End With
End Sub



You Sir, are Awesome!

Thank You Very Much!
 
Upvote 0
Hi RickXL,

What if we want to search more than one word. If we have around 10 word and we want to autofilter all 10 word one by one.
How would we write a code?
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top