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: 2

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,215,168
Messages
6,123,402
Members
449,098
Latest member
ArturS75

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