Forum Discussion
kyavari
Nov 13, 2025Occasional Reader
Cleaning up data with Macros
Hello everyone! I am cleaning up a worksheet that I use frequently to track weekly expenses and spending. I just discovered Macros and I want to use them to clean up my worksheet. Using Macros, how c...
NikolinoDE
Nov 14, 2025Platinum Contributor
Below is a simple, reliable way to create a macro-powered button that clears rows older than 3 months in Excel.
Sub ClearOldEntries()
Dim ws As Worksheet
Dim lastRow As Long
Dim checkDate As Date
Dim i As Long
' Change to your sheet name if needed
Set ws = ThisWorkbook.Sheets("Sheet1")
' Date threshold: 3 months before today
checkDate = DateAdd("m", -3, Date)
' Find last used row
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' Loop from bottom to top to avoid skipping rows
For i = lastRow To 2 Step -1 ' assumes row 1 is headers
If IsDate(ws.Cells(i, "A").Value) Then
If ws.Cells(i, "A").Value < checkDate Then
ws.Rows(i).ClearContents ' clear contents only
' or use: ws.Rows(i).Delete — if you want to delete the entire row
End If
End If
Next i
End Sub