Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


delete old date vba

Posted on 2011-02-17
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Accepted Solution

Deepak Lakkad earned 280 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 120 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
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…
Suggested Courses

618 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