Need VBA code to Filter Dates Tomorrow + 7 days

LtCmdrData

Board Regular
Joined
Jan 24, 2018
Messages
58
Office Version
  1. 365
Platform
  1. Windows
I need help writing some VBA code. Each morning I get a report of open orders. I'm working a week into the future so I want to filter on the due date column and delete all rows with a due date of tomorrow + 7 days into the future. For example if today is 9/19 then I want to filter for all rows with due dates of 9/20 thru 9/26 (7 days). Can someone please help me with this code? Thank you.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
May be you can try this code. I supposing that the data is on Sheet1 and there is a named range "dates".

Code:
Sub filterDate()
Dim date1  As Long
Dim date2 As Long
date1 = DateSerial(Year(Date), Month(Date), Day(Date)) + 1
date2 = DateSerial(Year(Date), Month(Date), Day(Date)) + 7
    
Sheet1.Range("dates").AutoFilter
Sheet1.Range("dates").AutoFilter Field:=1, Criteria1:= _
        ">=" & date1, Operator:=xlAnd, Criteria2:="<=" & date2
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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