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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel 2013 Problem 12 47
Splitting out Data 14 27
TT Auto DashBoard 4 26
Need Excel VBA Macro to Assign Two Digit Numbers to List 10 0
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 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

14 Experts available now in Live!

Get 1:1 Help Now