VBA - Deleting all rows in data for all past dates

monkeyhalf

New Member
Joined
May 25, 2022
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hi all,

Need help with a macro
Essentially we have a sheet of data, changes every day.
Many columns but Column C contains the column of end dates.
I want to filter the data, and then delete every row in the data where column c contains dates before today (the day we run the macro, so changing daily)
Is this possible? I tried messing around with it but I couldnt get it to work.

I'm in Australia so my system dates are dd/mm/yyyy if that matters...from googling online it seems Excel does dates as US format?
Thankyou very much, let me know if you need more information or examples
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Welcome to the MrExcel board!

Try this with a copy of your workbook.

VBA Code:
Sub DeletePriorDates()
  With Range("C1", Range("C" & Rows.Count).End(xlUp))
    .AutoFilter Field:=1, Criteria1:="<" & CLng(Date)
    .Offset(1).EntireRow.Delete
    .Parent.AutoFilterMode = False
  End With
End Sub
 
  • Like
Reactions: Zot
Upvote 0
Solution
Welcome to the MrExcel Message Board! :)

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Sorry about this! Will remember in future. Thankyou

Welcome to the MrExcel Message Board! :)

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Welcome to the MrExcel board!

Try this with a copy of your workbook.

VBA Code:
Sub DeletePriorDates()
  With Range("C1", Range("C" & Rows.Count).End(xlUp))
    .AutoFilter Field:=1, Criteria1:="<" & CLng(Date)
    .Offset(1).EntireRow.Delete
    .Parent.AutoFilterMode = False
  End With
End Sub
Amazing, thankyou very much, this worked!! Really appreciate it.
 
Upvote 0
You're welcome. Thanks for the follow-up. :)

(Might be a good idea to let the other forum(s) know that you have a solution here)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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