VBA to get today's date -2

milor17

New Member
Joined
Dec 1, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I'm doing an excel macro, everything is good except one point that I can't find the solution for.

The macro is on a file that I run once a week (on Wednesdays), every week.

I put a picture below to understand my explanations:

excel_ok.png


Basically: if the cell in the blue column is empty, the red column must be taken into account. On the opposite, if a date is in the blue column, it is the one that must be taken into consideration.
The green column is simply a "if" function to get the date as I explained above.

What I need: to have the date automatically filtered (with my macro) to the date of day -2 and before. So I'm going to run my file on Wednesday, I'll need the date (so the one to take into account as I explained before) to filter to Monday and all the other days before as well.
To understand a little better my filter history: it's as if I put a chronological filter with "before" and then "before or equal to..." and with the date of Monday.

Thank you very much in advance.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
It's not possible to give a specific answer without seeing your code, but suppose you have a loop like this:

Rich (BB code):
Dim R As Long ' Row
Dim NumRows As Long ' Number of rows

For R = 2 To NumRows

   If Cells(R, "P") <= Date - 2 Then
      ' Do your processing here
   End If

Next R
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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