Jack
Jack

Reputation: 275

Unselect all dates except current month (VBA EXCEL AUTOFILTER)

enter image description hereI am currently trying to unselect the current month using VBA I know how to select just the current month using VBA (the code is below) but I don't know how to unselect the current month while leaving the other months on.

Sheets("Sheet1").Range("d1:d6").AutoFilter Field:=4, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic

Upvotes: 1

Views: 1358

Answers (2)

A.S.H
A.S.H

Reputation: 29332

Try this:

Sheets("Sheet1").Range("d1:d20").AutoFilter Field:=1, Operator:=xlOr, _
     Criteria1:="<=" & Application.EoMonth(Date, -1), _
     Criteria2:=">" & Application.EoMonth(Date, 0)

Note:

  • EoMonth(Date, 0) marks the last day of current month

  • EoMonth(Date, -1) marks the last day of previous month

Upvotes: 1

WIbadeneralp
WIbadeneralp

Reputation: 71

Maybe you first try to deselect the filter

Cells.AutoFilter

Then you select all the other months

Upvotes: 0

Related Questions