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

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,233
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

ParamRay

Well-known Member
Joined
Aug 6, 2014
Messages
1,195
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
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,233
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hmmm...neither are working.
Did you install the code as a worksheet module or a standard module? Are your "dates" actual dates (i.e. numbers) or are they text?
 

cochrajl

New Member
Joined
Sep 19, 2014
Messages
27
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,433
Messages
5,528,738
Members
409,831
Latest member
KT50

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top