Filter get these days = Now - 5 days (by vba)

ngocanh87

Board Regular
Joined
Mar 16, 2016
Messages
85
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hello all,

I searched the forum but couldn't find this question, as the titles I want filter get these days = Now - 5 days (by vba)
Today 16 Feb, I want to filter get 15,14,13,12,11.

1676530549687.png
 

Attachments

  • 1676530144972.png
    1676530144972.png
    20.7 KB · Views: 6

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Select your Range according to your data. Filed 9 is for Column I.
VBA Code:
    Range("$A$1:$J$100").AutoFilter Field:=9, Criteria1:=">=" & Now-5, Operator:=xlAnd, Criteria2:="<" & Now
 
Upvote 1
Solution
Select your Range according to your data. Filed 9 is for Column I.
VBA Code:
    Range("$A$1:$J$100").AutoFilter Field:=9, Criteria1:=">=" & Now-5, Operator:=xlAnd, Criteria2:="<" & Now
Hi,

After fillter it as below but I want Date not have Time (ex: 17/02/2023 & 22/02/2023) Thank you

1677048285653.png
 
Upvote 0
This should work:
VBA Code:
    Range("$A$1:$J$100").AutoFilter Field:=9, Criteria1:=">=" & Date(Now)-5, Operator:=xlAnd, Criteria2:="<" & Date(Now)
 
Upvote 0
Try:
VBA Code:
    Range("$A$1:$J$100").AutoFilter Field:=9, Criteria1:=">=" & Date()-5, Operator:=xlAnd, Criteria2:="<" & Date()
 
Upvote 0
Hello,

Sorry I want asked more, Column I is Text and when I run vba it can;t correct, how can I convert Date (dd/MM/YYYY). Thank you

1678086370865.png
 
Upvote 0

Forum statistics

Threads
1,224,862
Messages
6,181,464
Members
453,044
Latest member
rgbenson1

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