• Delete Range of Dates (Excel 2003)

    Author
    Topic
    #455364

    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

    Viewing 1 reply thread
    Author
    Replies
    • #1133149

      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

    • #1133161

      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.

    Viewing 1 reply thread
    Reply To: Delete Range of Dates (Excel 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: