[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

delete old date vba

Posted on 2011-02-17
2
Medium Priority
?
384 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 280 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 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")
Wend

End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 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