Customer filter based on formula in VBA

stephen antoine

Board Regular
Joined
Jun 4, 2008
Messages
128
Good morning all,

Can someone tell me how to filter records in VBA based on a formula? I tried the following code but it doesn't work:

Code:
Sheets("NE-SE All Open Orders").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=10, Criteria1:="<=(today()-365)"
    
    'The line above is attempting to show only those records
    'that are over 1 year older than today
    
    Cells.Copy
    Sheets.Add.Name = "NE-SE Orders Older Than 1 Yr"
    ActiveSheet.Paste

I just want to be able to filter my data for all records older than one year and then copy the data to a new tab...

Please help:confused:
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try

Code:
MyVal = Date - 365
Sheets("NE-SE All Open Orders").Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=10, Criteria1:="<=" & MyVal
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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