none
Autofilter Using Now In An Array RRS feed

  • Question

  • Hello forum members, need help tweaking this autofilter code, I want to show anything in field 32 that has any day in the previous month. I was using "-30" but that gives me anything 30 days prior and what I really want is anything in the previous month.

        ActiveSheet.Range("$A$6:$ET$1000").AutoFilter Field:=32, _
               Operator:=xlFilterValues, Criteria2:=Array(1, Now - 30)

    any thoughts?


    MEC

    Monday, October 3, 2016 7:20 PM

Answers

  • Hi mecerrato,

    Accordingt to your description, you could modify like below:
    ActiveSheet.Range("$A$6:$ET$1000").AutoFilter Field:=32, Criteria1:=">=" & DateAdd("m", -1, Date) - Day(Date) + 1, Operator:=xlAnd, Criteria2:="<" & Date - Day(Date) + 1

    For more information, click here to refer about Range.AutoFilter Method (Excel)

    Thanks for your understanding.
    • Proposed as answer by David_JunFeng Friday, October 14, 2016 9:33 AM
    • Marked as answer by David_JunFeng Monday, October 17, 2016 2:30 PM
    Tuesday, October 4, 2016 2:14 AM