Input box for date...then delete

Posted on 2007-09-28
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

    Use an InputBox, like this:

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

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

    LVL 80

    Accepted Solution

    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

    That is so KOOOL

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Employees list 3 33
    recovering Excel 2016 file 2 25
    Min Month 11 31
    Update Column Based On Match 3 14
    Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
    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.
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now