Solved

delete old date vba

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

example:
now is   16.02.2011 19:45
                     A

1       01.02.2011 19:45

2       02.02.2011 19:45

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

4                

5       19.02.2011 15:00

6       20.02.2011 14:45

7

8       26.02.2011 15:00
0
Comment
Question by:thmh
2 Comments
 
LVL 11

Accepted Solution

by:
Deepak Lakkad earned 70 total points
ID: 34915236
Hi

Create a Macro, name it "DeleteDates".

Write following code for the macro.


Sub DeleteDates()
'
' DeleteDates Macro
'

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

Open in new window


Run the macro, it will delete records

- Deepak Lakkad
0
 
LVL 6

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")
Wend

End Sub
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

860 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