Forum Discussion
heathermarie923
Sep 13, 2022Copper Contributor
Need help with VBA code to clear content of a range of cells based on today's date.
Good morning,
I am looking for help to formulate VBA Code.
I need to clear the contents of Columns C:F if Column F is less than today's date. Can anyone help me with this? Please and thank you in advance!
- no limit per app like net limiter 4, no limit for 5g modem, or any other conditional options to make useful....
4 Replies
Sort By
- OliverScheurichGold Contributor
Sub clear_C_to_F() Dim i As Long For i = 2 To 1000 If Cells(i, 6) < Date Then Range(Cells(i, 3), Cells(i, 6)).Clear Else End If Next i End Sub
Maybe with these lines of code. In the attached file you can click the button in cell H2 to run the macro.
- heathermarie923Copper ContributorThis is great! Is there anyway to automate the process when the spreadsheet is opened?
- OliverScheurichGold Contributor
Without clicking the button?
Private Sub Worksheet_Activate() Dim i As Long For i = 2 To 1000 If Cells(i, 6) < Date Then Range(Cells(i, 3), Cells(i, 6)).Clear Else End If Next i End Sub
Maybe with the Worksheet_Activate event.
After opening the attached file the sheet "Tabelle1" is shown with all the data. If you select "Tabelle3" and then again activate "Tabelle1" the Worksheet_Activate event is executed.