Macro to show only last seven days based on a column

shabbaranks

New Member
Joined
Sep 14, 2011
Messages
16
Hi all..

Im trying to get filter my exported Access data to only show content from the last seven days based on a column. At the moment the sheet has data ranging from 01/01/2011 until today. What I would like to do is use a macro to just show data for the last 7 days - is this possible?

Thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
This assumes the dates are in column A

Code:
Sub Last_7_Days()
    Range("A1", Range("A" & Rows.Count).End(xlUp)).AutoFilter Field:=1, Criteria1:=">=" & (Date - 7)
End Sub
 
Upvote 0
Thanks for that, if I assign the macro and run it I get a blank return. If I then go into the filter and change it to 1 day either way it works - any ideas why this is?

Thanks
 
Upvote 0
My first guess is that your dates are Text-dates and not serial dates.

Dates And Times In Excel

There are a couple of ways you can convert en masse the text-dates to serial dates.
  • Select the column with the dates.
  • Select from the menu Data\Text to Columns
    • Select Delimited and Next
    • Deselect all the delimiters and Next
    • Select Column data format: Date
    • Finish
 
Upvote 0

Forum statistics

Threads
1,224,608
Messages
6,179,872
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top