I am trying to filter all dates in a column within 1 week/7 days in the future from today using the same autofilter method in VBA shown below. My column of interest this time is Field:=53
ActiveSheet.ListObjects("Table22").Range.AutoFilter Field:=129, Criteria1:= _
"UPCOMING"
I'm wondering if this is possible to do, and if so how?
CodePudding user response:
From today till this day next week:
.AutoFilter Field:=53, Criteria1:=">=" & Date, Operator:=xlAnd, Criteria2:="<=" & Date 7
You can also use special values to quickly set the filter to "this week" or "next week". See this list all possible special values.
'This Week
.AutoFilter Field:=53, Criteria1:=xlFilterThisWeek, Operator:=xlFilterDynamic
'Next Week
.AutoFilter Field:=53, Criteria1:=xlFilterNextWeek, Operator:=xlFilterDynamic
CodePudding user response:
You can set the filter like this:
ActiveSheet.ListObjects("Table22").Range.AutoFilter 129, ">=" & CLng(Date), xlAnd, "<=" & CLng(DateAdd("d", 7, Date))
To filter for dates it is necessary to convert them to a long value, otherwise the filter won't work.