Macro to delete entire row if date in column L is older than 7 days....

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Code:
Sub DeleteOlderThanSeven()
Dim lR As Long, R As Range, i As Long
lR = Range("L" & Rows.Count).End(xlUp).Row
Set R = Range("L1:L" & lR)
Application.ScreenUpdating = False
For i = lR To 1 Step -1
    If IsDate(R.Cells(i)) Then
        If Date - R.Cells(i).Value > 7 Then
            R.Rows(i).EntireRow.Delete
        End If
    End If
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
Sub DeleteRows()

    Dim Rang As Range
    Dim Cell As Range
    Dim Arr() As Long
    Dim Num As Long
    Dim i As Long
    
    With ActiveSheet    'change as necessary
        Set Rang = Intersect( _
            .Columns("L"), _
            .UsedRange)
    End With
    
    Num = 0
    For Each Cell In Rang
        If IsDate(Cell.Value) Then
            If Cell.Value < Date - 7 Then
                Num = Num + 1
                ReDim Preserve Arr(1 To Num)
                Arr(Num) = Cell.Row
            End If
        End If
    Next Cell
    
    For i = Num To 1 Step -1
        ActiveSheet.Rows(Arr(i)).Delete
    Next i

End Sub
 
Upvote 0
Its working now...not sure what the problem was. I have a lot of macros that merge files from different sources. That may have had something to do with it.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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