Delete entire row if dates are 15 days older than today's

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have been searching the web for some days now and can't figure out the exact code I need.

I want to delete all rows with dates in column B that are older than today's date.

Thank you in advance
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi

try

Rich (BB code):
Sub DeleteRows()
    Dim c As Range, DeleteRange As Range, DataRange As Range
    Dim LR As Long
    
'change sheet name as required
    With Worksheets("Sheet1")
'find last row in range
        LR = .Cells(.Rows.Count, "B").End(xlUp).Row
'range you are searching
        Set DataRange = .Range("B1:B" & LR)
    End With


    DataRange.EntireRow.Hidden = False


    For Each c In DataRange.Cells
        If IsDate(c.Value) Then
            If Date - DateValue(c.Value) > 15 Then
                If DeleteRange Is Nothing Then
                    Set DeleteRange = c
                Else
                    Set DeleteRange = Union(DeleteRange, c)
                End If
            End If
        End If
    Next c
'delete all matched rows in one go
    If Not DeleteRange Is Nothing Then DeleteRange.EntireRow.Delete
End Sub

Change sheet name shown in RED as required.

Dave
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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