So, i got some great help a couple years ago in getting a VB Macro to run to delete days within an excel sheet that were X amount of days old. It was also setup to count and add certain even together. So i am working on using that VB for another sheet and am try to modify it to work and having an issue. In the original one column A had a standard date 20220101 and it would look for dates older than they and delete. No when they do it, they will merger the entire row columns A-L and enter the date as "Monday, January 3, 2022". Does the VB have to be adjusted to see the date that way? Also, in the original VB i was tracking trucks going from "Site 1", "site 2" etc, so as it would delete it would add to another cell to keep track of the total as well, but not in this sheet they use arrows "↑" and "↓". Does VB recognize using those arrows?
Here is a copy of the VB i had entered for now, this is definitely above me, so trying to make it work so can use any help thanks.
Here is a copy of the VB i had entered for now, this is definitely above me, so trying to make it work so can use any help thanks.
VBA Code:
Private Sub Workbook_Open()
Sheets("Delivery").Unprotect
DaysOld = 75
CheckRow = 4 'This is the first row to check - it assumes that rows 1-2-3 are headers
RecordsFound = 0 'This is a counter of the number of rows deleted
Application.EnableEvents = False
Application.ScreenUpdating = False
With Sheets("Delivery")
Do 'Go through records, if the record is old enough to delete then delete.
'Stop when column A is blank
If .Range("A" & CheckRow).Value = "" Then Exit Do
If .Range("A" & CheckRow).Value < (Now - DaysOld) Then
'This record needs to be deleted - check if it contains any Job Sites and update the totals
If .Range("E" & CheckRow).Value = "↑" Then .Range("AA5").Value = .Range("AA5").Value + 1
If .Range("E" & CheckRow).Value = "↓" Then .Range("AF5").Value = .Range("AF5").Value + 1
'Then delete the record
.Range("A" & CheckRow & ":M" & CheckRow).Delete (xlShiftUp)
RecordsFound = RecordsFound + 1
Else
CheckRow = CheckRow + 1
End If
Loop
End With
Application.ScreenUpdating = True
Application.EnableEvents = True
Sheets("Delivery").Protect
End Sub
Last edited by a moderator: