Dynamic auto filter...

L

Legacy 264643

Guest
Just curious,
What would I have to do to make the following code I recorded for using an auto filter Dynamic?
Code:
ActiveSheet.Range("$A$2:$G$1138").AutoFilter Field:=5, Criteria1:="Yes"
    ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort. _
    SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort. _
    SortFields.Add Key:=Range("C2:C1138"), SortOn:=xlSortOnValues, Order:= _
    xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").AutoFilter. _
        Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Chris Mack

Well-known Member
Joined
Jun 18, 2013
Messages
803
It depends what you want it to be dynamic for.

One thing I can think of would be like:

Rich (BB code):
n = Inputbox("Last row in range:")

or

n = Cells(Rows.Count, 1).End(xlUp).Row

ActiveSheet.Range("$A$2:$G$" & n).AutoFilter Field:=5, Criteria1:="Yes"
I would think it would depend on what kind of dynamicity you wanted though.

Chris.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,195,909
Messages
6,012,249
Members
441,687
Latest member
urimagic

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
Top