ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Filter between dates (https://www.excelbanter.com/excel-programming/318609-filter-between-dates.html)

Dominique Feteau[_2_]

Filter between dates
 
I recorded a macro that would filter the dates in column A between two
dates. I looked at the code and made some edits and came up with this after
a little bit of tweaking:

Sub ChangeWeek()

Dim weekbegin As Date
Dim weekend As Date

weekbegin = InputBox("Week Beginning")
weekend = InputBox("Week Ending")
Selection.AutoFilter Field:=1, Criteria1:=weekbegin, Operator:=xlOr _
, Criteria2:=weekend

End Sub

Only problem is that the code above only shows me those 2 dates. I need the
dates in between too.

I know its something simple, but I cant figure it out. Any help would be
cool.

Thanks
Niq



Debra Dalgleish

Filter between dates
 
Use the And operator, and = and <= for the date operators:

Selection.AutoFilter Field:=1, _
Criteria1:="=" & weekbegin, Operator:=xlAnd, _
Criteria2:="<=" & weekend


Dominique Feteau wrote:
I recorded a macro that would filter the dates in column A between two
dates. I looked at the code and made some edits and came up with this after
a little bit of tweaking:

Sub ChangeWeek()

Dim weekbegin As Date
Dim weekend As Date

weekbegin = InputBox("Week Beginning")
weekend = InputBox("Week Ending")
Selection.AutoFilter Field:=1, Criteria1:=weekbegin, Operator:=xlOr _
, Criteria2:=weekend

End Sub

Only problem is that the code above only shows me those 2 dates. I need the
dates in between too.

I know its something simple, but I cant figure it out. Any help would be
cool.

Thanks
Niq




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html


Dominique Feteau[_2_]

Filter between dates
 
i knew it was easy.

thanks
niq

"Debra Dalgleish" wrote in message
...
Use the And operator, and = and <= for the date operators:

Selection.AutoFilter Field:=1, _
Criteria1:="=" & weekbegin, Operator:=xlAnd, _
Criteria2:="<=" & weekend


Dominique Feteau wrote:
I recorded a macro that would filter the dates in column A between two
dates. I looked at the code and made some edits and came up with this
after a little bit of tweaking:

Sub ChangeWeek()

Dim weekbegin As Date
Dim weekend As Date

weekbegin = InputBox("Week Beginning")
weekend = InputBox("Week Ending")
Selection.AutoFilter Field:=1, Criteria1:=weekbegin, Operator:=xlOr _
, Criteria2:=weekend

End Sub

Only problem is that the code above only shows me those 2 dates. I need
the dates in between too.

I know its something simple, but I cant figure it out. Any help would be
cool.

Thanks
Niq



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html





All times are GMT +1. The time now is 02:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com