0

I'm trying to sort an Excel worksheet by date range using VBA. I need to filter for all entries that are within a week of the current date.

The worksheet is arranged into columns (A to S). Column 'I' stores the dates I want filtered.

Below is the latest code i've tried (i've tried a few variations... and just cant figure it out).

Dim A As Date
Dim b As String
Dim c As Long
A = Date
A = DateSerial(Year(A), Month(A), Day(A))
b = Format(A - 7, "yyyy, mm, dd")
c = b    
With ActiveSheet
    .Range("$A:$S").AutoFilter Field:=9, Criteria:=">" & c
    End With

Thanks in advance for your help with this.

GTD

2
  • Is this format "yyyy, mm, dd" the format values in column I are formatted? that is very surprising way of storing a Date Commented May 21, 2015 at 10:29
  • Hi -- date format in column 'I' is mm/dd/yyy. Commented May 21, 2015 at 10:52

2 Answers 2

1

try this:

 ActiveSheet.Range("$A$1:$S$" & ActiveSheet.UsedRange.Rows.Count).AutoFilter Field:=9, Criteria1:=">" & Format(Date - 7, "mm/dd/yyyy")
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

Dim A As Date
A = Date

With ActiveSheet
    .Range("$A:$S").AutoFilter Field:=3, Criteria1:=">" & A - 7
End With

1 Comment

Thanks for looking into this for me. It didn't work as i needed it to i'm afraid. It did filter though :). For me, 'Field:=3' should have been 'Field:=9'. Also, it seemed to remove all dates from the filter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.