Marco to delete rows with a future date

markman235

Board Regular
Joined
May 10, 2011
Messages
52
Hi everyone,

I am to write a macro for Excel 365 that will look at a date and delete the row if it is greater than today. I found one that was from a few years ago online, but it doesn't seem to work.

The date is in column F

Sub delfutureDays()
Dim cl As Long
For cl = Range("F2").End(xlDown).Row To 2 Step -1
If Cells(cl, "F") > Date Then Rows(cl).EntireRow.Delete
Next
End Sub

Any thoughts?

Mark
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Need to reference .Value or .Value2:

VBA Code:
Sub delfutureDays()
    Dim cl As Long
    For cl = Range("F2").End(xlDown).Row To 2 Step -1
    If Cells(cl, "F").Value2 > Date Then Rows(cl).EntireRow.Delete
        Next
    
    End Sub
 
Upvote 1
Other than the method for finding the last row doesn't account for blanks cells (the code will stop looking past first blank cell it meets) the code should work fine.

Need to reference .Value or .Value2
VBA defaults to .Value when omitted from a cell
 
Upvote 1
Other than the method for finding the last row doesn't account for blanks cells (the code will stop looking past first blank cell it meets) the code should work fine.


VBA defaults to .Value when omitted from a cell
How can i ask it to ignore blank cells?
 
Upvote 0
Try (if the cells are truly blank/empty)...

VBA Code:
For cl = Range("F" & Rows.count).End(xlUp).Row To 2 Step -1
 
Upvote 0
Solution
Try (if the cells are truly blank/empty)...

VBA Code:
For cl = Range("F" & Rows.count).End(xlUp).Row To 2 Step -1
So the good news is that it seems to work, except that it deletes everything on the sheet regardless of the date value...

Here is what I now have:

Sub delfutureDays()
Dim cl As Long
For cl = Range("F" & Rows.Count).End(xlUp).Row To 2 Step -1
If Cells(cl, "F").Value2 > Date Then Rows(cl).EntireRow.Delete
Next

End Sub
 
Upvote 0
Are your dates "real" dates or are they text?
 
Upvote 0
Change the format of the cells to General, do the cells still look like dates or do they change to a number?
 
Upvote 0
Change the format of the cells to General, do the cells still look like dates or do they change to a number?
No, they stay the same. Here's a screenshot.

1726690013568.png
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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