VBA Clear Contents of Cells Less than Today's Date

mdeni0528

New Member
Joined
Aug 11, 2021
Messages
16
Office Version
  1. 2010
Platform
  1. Windows
Hi!

I'm hoping you can help me with a VBA formula that clears the contents of dates in cells based on an end date that is less than today's date. My worksheet has a start date and an end date for multiple segments and these dates are associated with one another. The clear contents command needs to be triggered by the end date when it's less than today's date. The end date needs to be cleared from the worksheet as well as the start date associated with it. I have multiple columns of start dates and end dates, so I need to apply this command to multiple columns. I need a formula similar to the one below but for entire columns since this only applies to one cell and is not written correctly. My start and end dates that should be deleted are highlighted in red using a conditional format. Please help! I don't know VBA language at all! Thank you!


If Date > Range("C9").Value then Range("C9").ClearContents
If Range("B9")> isnotblank and Range("C9")Then Range("B9").ClearContents
Capture_VBA Help Example.PNG
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This worksheet below pulls dates from the first worksheet. The dates still exist on the first worksheet but the VBA runs when I open the file showing this worksheet and deletes dates which still exist on the first spreadsheet in the worksheet. Does that make sense?


1633550145663.png
 
Upvote 0
Also, the dates below are just pulled in using a vlookup from the first worksheet.
 
Upvote 0
In your images I do not see the rows and columns of excel.
 
Upvote 0
I am afraid that the macro is not ready for any new designs that you generate.

1633625204596.png
 
Upvote 0
VBA Code:
  [B]For Each sh In Sheets[/B]
    sh.Unprotect "***"
    For i = 9 To sh.Range("A" & Rows.Count).End(3).Row
      For j = 3 To sh.Cells(i, Columns.Count).End(1).Column Step 2
        [B]If Date > sh.Cells(i, j).Value Then[/B]
The macro can work for all the sheets of the book, it can be 1 or 100 sheets; and that they also comply with the condition of the date.
But you must show the design of each sheet. If they are the same there is no problem, but if you change the design, then the macro must be adapted.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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