Input box for date...then delete

Posted on 2007-09-28
Medium Priority
Last Modified: 2008-01-09
I hope this is not too much to ask?
I need a input box for a macro that will STOP the macro and ask for a date...then delete that date and any date les than.  (Is less than or equal to)
The date column K.
Question by:eureka15
LVL 27

Expert Comment

ID: 19981928
Use an InputBox, like this:

    Dim sDate As String
    sDate = InputBox("Please provide date")

    If IsDate(sDate) = True Then
        MsgBox sDate
    End If

LVL 81

Accepted Solution

byundt earned 2000 total points
ID: 19982038
Here is a macro that will delete your data (entire rows) if column K date is on or before a user-specified value:

Sub DeleteDates()
Dim dat As Date
Dim rg As Range
Dim i As Long
dat = Application.InputBox("Please pick the latest date to be deleted", Type:=1)
If dat = 0 Then Exit Sub
Application.ScreenUpdating = False
Set rg = [K2]       'First date to examine
Set rg = Range(rg, Cells(Rows.Count, rg.Column).End(xlUp))
For i = rg.Rows.Count To 1 Step -1
    If rg.Cells(i,1) <> "" Then       'To delete rows with blanks also, then delete this statement and the End If
        If rg.Cells(i, 1) <= dat Then rg.Rows(i).EntireRow.Delete
    End If
Application.ScreenUpdating = True
End Sub


Author Comment

ID: 19982182
That is so KOOOL

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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