[Solved] Delete rows base on the input box date [closed]


You can try this, just set ws to whatever worksheet you have your dates in

Sub datechecker()

    Dim inputBoxText As String
    Dim inputBoxDate As Date
    Dim lastRow As Integer
    Dim row As Integer
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Worksheets(1)

    With ws    

    lastRow = .Cells(.Rows.Count, "K").End(xlUp).row
    inputBoxText = InputBox("Please enter a Date:", "Date Input Box", "Type Here", 10, 10)

    If IsDate(inputBoxText) Then
        inputBoxDate = CDate(inputBoxText)
    Else
        MsgBox "Please enter a correct date"
        Exit Sub
    End If

    On Error GoTo Handler
    For row = 1 To lastRow
        If Len(.Range("K" & row).Value) > 0 Then
            If inputBoxDate > CDate(.Range("K" & row).Value) Then
                .Rows(row).EntireRow.Delete
                row = row - 1
            End If
        End If
    Next

    End With

    Exit Sub

Handler:
    MsgBox "Please make sure cells are formatted to date"

End Sub

2

solved Delete rows base on the input box date [closed]