首页 > 解决方案 > VBA,从输入框中过滤输入以删除行

问题描述

通过导出数据 excel 创建一个新的工作簿。我有一个输入框要输入,应该导出哪个日期,使用以下代码,效果很好。

ReEnter:
Dim AddDate As String

    AddDate = InputBox("Enter date for export.", "Enter date", "DD.MM.YYYY")
        If Not Format(AddDate, "DD.MM.YYYY") = AddDate Then
            MsgBox "Wrong format. Use DD.MM.YYYY."
            GoTo ReEnter
        Else
            If AddDate = "" Then
            Workbooks("PEKLAR.xlsm").Close
            GoTo The_End
            End If
        End If

Workbooks("PEKLAR.xlsm").Activate

Dim FoundRange As Range

Set FoundRange = Range("A:A").Find(what:=DateValue(AddDate), LookIn:=xlFormulas, lookat:=xlWhole)


If FoundRange Is Nothing Then
    MsgBox "Date not found. Please try again."
    GoTo ReEnter
Else

Dim i As Long
    Application.EnableEvents = False
    With Worksheets("PEKLAR")
        For i = .Cells(.Rows.Count, 1).End(xlUp).Row To 3 Step -1
            Select Case LCase(.Cells(i, 1).Value)
                Case AddDate
                    'do nothing
                Case Else
                    .Rows(i).EntireRow.Delete
            End Select
        Next i
        
        Workbooks("PEKLAR.xlsm").Worksheets("PEKLAR").Range("A2:W2500").AutoFilter Field:=22, Criteria1:="kein Fehler"
        Workbooks("PEKLAR.xlsm").Worksheets("PEKLAR").Range("A3:W2500").SpecialCells(xlCellTypeVisible).EntireRow.Delete
        On Error Resume Next
        Workbooks("PEKLAR.xlsm").Worksheets("PEKLAR").ShowAllData
    End With
    Application.EnableEvents = True
    Workbooks("PEKLAR.xlsm").Close True

End If

现在我希望用户一次输入多个日期。我已经尝试使用 split(AddDate, ",") 但我没有得到正确的代码来拆分日期,如果找到输入的日期/日期(也只有一个日期),请查看 A 列,删除包含任何其他日期的行(仅保留输入的日期),然后删除第 22 列中包含“kein Fehler”的行。

任何帮助都会得到帮助。

先感谢您。

标签: vbafilteringinputbox

解决方案


推荐阅读