Hello,
In VBA I am looking to delete entire row rows based on the age of the date in column AI. I am currently deleting rows older than 31 days, but since it deletes one row at a time it takes a long times since there are thousands of rows to delete each time I update it. I am not the greatest with VBA. Just a basic understanding and most of the codes I write are just Frankensteined together, so having a hard time figuring this out myself.
Instead of looping through the code line by line, I'm thinking it might be possible to set my range dynamically, but not sure how to go about doing that. My data is always organized from oldest to newest so I dont need to search the whole data set for rows to delete. I would just need to delete from row 2 to the last row that is older than 31 days.
This is the delete code I am currently using in my macro, but its too slow to be viable. (I just call it the main VBA so I can easily turn it on and off when running the main code)
Thanks for any advice or help!
In VBA I am looking to delete entire row rows based on the age of the date in column AI. I am currently deleting rows older than 31 days, but since it deletes one row at a time it takes a long times since there are thousands of rows to delete each time I update it. I am not the greatest with VBA. Just a basic understanding and most of the codes I write are just Frankensteined together, so having a hard time figuring this out myself.
Instead of looping through the code line by line, I'm thinking it might be possible to set my range dynamically, but not sure how to go about doing that. My data is always organized from oldest to newest so I dont need to search the whole data set for rows to delete. I would just need to delete from row 2 to the last row that is older than 31 days.
This is the delete code I am currently using in my macro, but its too slow to be viable. (I just call it the main VBA so I can easily turn it on and off when running the main code)
VBA Code:
Sub Delete()
Application.ScreenUpdating = False
Dim i As Long
Dim LastRow As Long
With Sheets("Data")
LastRow = .Cells(.rows.Count, "AI").End(xlUp).Row
For i = LastRow To 2 Step -1
If DateDiff("d", .Range("AI" & i).Value, Date) > 31 Then
.rows(i).Delete
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
Thanks for any advice or help!