Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2005
    Location
    Asia Pacific, Bangkok Metropolis
    Posts
    378
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete Range of Dates (Excel 2003)

    Hi

    Is there a marco to perform the following :

    1. Pop out a window to ask the user to input the beginning date in MM/DD/YY format.
    2. Pop out another window to ask the user to input the ending date in MM/DD/YY format.
    3. Then the macro deletes rows based on the entered date period (all
    rows between the beginning date and the ending date will be deleted).

    In the target excel worksheet, dates in column B.

    TIA

    regards
    Hope this is helpful

    francis, <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

    My Reading

    Pivot Table 101
    Pivot Table
    Array

  2. #2
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Range of Dates (Excel 2003)

    Hi Franciz

    I am sure that you will get a "proper answer" later on but I have a user from hat has a date from and a date to field on it. On the form there is a calendar control and I highlight a date that I want to start a holiday from and click a button 'from date' then select and end date and click a button 'to date'

    Private Sub cmdDateFrom_Click()
    Me.txtDateFrom = Format(Me.Calendar1, "dd/mm/yyyy")
    End Sub

    Private Sub cmdDateTo_Click()
    Me.txtDateTo = Format(Me.Calendar1, "dd/mm/yyyy")
    End Sub

    But how you code a button to delete between those dates is beyond me.

    Steve
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Range of Dates (Excel 2003)

    Try this:

    Sub DeleteBetween()
    Dim dtmStart As Date
    Dim dtmEnd As Date
    Dim r As Long
    Dim m As Long
    On Error GoTo ErrHandler
    dtmStart = InputBox("Enter start date.")
    dtmEnd = InputBox("Enter end date")
    m = Cells(Rows.Count, 2).End(xlUp).Row
    For r = m To 2 Step -1
    If IsDate(Cells(r, 2)) Then
    If Cells(r, 2) >= dtmStart And Cells(r, 2) <= dtmEnd Then
    Rows®.Delete
    End If
    End If
    Next r
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    End Sub

    Note: if you read this reply in an e-mail notification or digest, the "greater than or equal to" and "less than or equal to" symbols may be mangled. Please visit the website to view the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •