VBA delete rows with older dates but not rows with blank cells

morkar

New Member
Joined
Mar 8, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hello, I am trying to delete rows with older dates (older than 60 days) in column L but the macro below also deletes rows with blank values in that column. How can I adjust the macro so it does not delete the rows with blank values?


Sub DeleteOldTerms()
Dim lr As Long, I As Long
With Sheets("ExportedData")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Range("L" & Rows.Count).End(xlUp).Row
For I = lr To 4 Step -1
If Range("L" & I).Value <= Date - 60 Then Rows(I).Delete
Next I
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End With
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,791
Try

VBA Code:
Sub DeleteOldTerms()
Dim lr As Long, I As Long
With Sheets("ExportedData")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Range("L" & Rows.Count).End(xlUp).Row
For I = lr To 4 Step -1
If Range("L" & I).Value <= Date - 60 Then
    If Range("L" & I).Value <> "" Then Rows(I).Delete
    End If
End If
Next I
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End With
End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,130,119
Messages
5,640,218
Members
417,131
Latest member
Seanr19871

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
Top