0

I don't have enough reputation to comment on the original post so I think I have to ask here... Excel VBA - filter rows within dynamic range I'm trying to change my VBA to filter rows with dynamic ranges. My code is below but I'm not sure what to change it to?

ActiveSheet.Range("$A$1:$K$18791").AutoFilter Field:=8, Criteria1:=Array( _
    "Custom", "Health & Welfare", "Insurance", "Retirement & Savings"), Operator:= _
    xlFilterValues

I see from the other post the reply has

ActiveSheet.UsedRange.AutoFilter  Field:=10, Criteria1:="FALSE"

Would my code be;

ActiveSheet.UsedRange.AutoFilter  Field:=8, Criteria1:=Array( _
    "Custom", "Health & Welfare", "Insurance", "Retirement & Savings"), Operator:= _
    xlFilterValues

My main question is when ".UsedRange" is used, do I have to set the range first? Could someone provide me with the edits I need if needed? In short, I'm trying to filter column K by the criteria but it doesn't end in row 18791 each week so I'm trying to make sure my code grabs the varying data each week.

  • No, you don't have to set `UsedRange`. Another option is to [find the last row](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba). – BigBen Aug 25 '20 at 13:31
  • So by putting UsedRange, it's just selecting all rows used in the file? If so, is my updated code there correct? – LittleAuditorium Aug 25 '20 at 13:37
  • https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.usedrange – BigBen Aug 25 '20 at 13:40

0 Answers0