delete old date vba

Posted on 2011-02-17
Last Modified: 2012-05-11
hy ,
have column A filed with dates, need macro to delete old dates (offset (-1, 2))

now is   16.02.2011 19:45

1       01.02.2011 19:45

2       02.02.2011 19:45

3                                                    macro will delete range A1:C3 and shift cells up


5       19.02.2011 15:00

6       20.02.2011 14:45


8       26.02.2011 15:00
Question by:thmh
LVL 11

Accepted Solution

Deepak Lakkad earned 70 total points
ID: 34915236

Create a Macro, name it "DeleteDates".

Write following code for the macro.

Sub DeleteDates()
' DeleteDates Macro

    If Range("A1").Value < DateTime.Now Then
        Selection.Delete Shift:=xlUp
        GoTo StartPoint
        Exit Sub
    End If
End Sub

Open in new window

Run the macro, it will delete records

- Deepak Lakkad

Assisted Solution

by:Eric Zwiekhorst
Eric Zwiekhorst earned 30 total points
ID: 34915288
Dear THNM,

how can the macro distinguish what is OLD dates?
Do you mean everything before now?

Then your macro would be something like

Sub deleteold()
Dim dateold, datenew As Variant
dateold = Format(Cells(1, 1), "d-MM-yyyy hh:mm:ss")
datenew = Format(Now(), "d.MM.yyyy hh:mm:ss")
While dateold < datenew
Cells(1, 1).EntireRow.Delete
dateold = Format(Cells(1, 1), "d-MM-yyyy hh:mm:ss")
datenew = Format(Now(), "d.MM.yyyy hh:mm:ss")

End Sub

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I need help embedding an image as HTML in my application 3 48
copy the content of word to outlook 3 48
Problem to open text file 11 68
Automating Excel Weekly Report 13 53
If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now