PDA

View Full Version : Solved: Criteria1:=strDate



davmec93
10-18-2010, 12:01 PM
Hi all! I have some code that I run on a spread sheet of data (duh), this code allows me to select a specific date. What I would like to be able to do is pick a date and get the date I pick plus the next 5 days. I've tried Criteria1:=strDate +5 but it doesn't work. Any ideas? Here is my current code and thank you for taking the time to look.
strDate = InputBox("Please enter start date", "Date Entry")
strDate = ">=" & strDate
If strDate = "" Then
Exit Sub
End If
Selection.AutoFilter Field:=3, Criteria1:=strDate, Operator:=xlAnd

This gives me the date I enter plus everything greater than that...

JKwan
10-18-2010, 12:34 PM
Try this

Dim strDate As String

strDate = InputBox("Please enter start date", "Date Entry")
If Not (IsDate(strDate)) Then
Exit Sub
End If
Selection.AutoFilter Field:=3, Criteria1:=">=" & strDate, Operator:=xlAnd _
, Criteria2:="<=" & DateValue(strDate) + 5

davmec93
10-18-2010, 12:51 PM
Try this

Dim strDate As String

strDate = InputBox("Please enter start date", "Date Entry")
If Not (IsDate(strDate)) Then
Exit Sub
End If
Selection.AutoFilter Field:=3, Criteria1:=">=" & strDate, Operator:=xlAnd _
, Criteria2:="<=" & DateValue(strDate) + 5


Hey, works good! It actually pulls 6 days but that's no biggie...I can mod that. Thank you for your time, I really do appreciate it.:friends:

Aussiebear
10-18-2010, 01:39 PM
What I would like to be able to do is pick a date and get the date I pick plus the next 5 days.

The code that JKwan gave you was based on what you asked for.

davmec93
10-18-2010, 01:47 PM
The code that JKwan gave you was based on what you asked for.
You are correct!