我编写了基于单列过滤器的SINGLE输入值删除行的代码,我想编辑它来处理来自同一列过滤器的多个输入值。
数据库的标题位于A4:Z上。
Option Explicit
Sub Test()
Dim ws As Worksheet
Dim lastRow As Long
Dim rng As Range
Dim myValue As Variant
'set sheet reference
Set ws = ActiveSheet
'turn off autofilter
ws.AutoFilterMode = False
'get last row
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'set range to filter
Set rng = ws.Range("A4:Z" & lastRow)
'get user input
myValue = InputBox("Periods to delete?")
'set filter
rng.AutoFilter Field:=8, Criteria1:=myValue
'delete visible rows
rng.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
'show remaining rows by removing autofilter
ws.AutoFilterMode = False
End Sub
输入框目前占用一个句点(月份号)。我希望它采取多种值,如#2,3; 2,3,4'。这将删除2(feb),3(3月),4(4月)。
真的不知道下一步该怎么做,我还是vba的新手。
答案 0 :(得分:1)
尝试用此替换自动过滤器线。它假定值在逗号分隔的输入框中输入。它将它们转换为数组。
rng.AutoFilter Field:=8, Criteria1:=Array(Split(myValue, ",")), Operator:=xlFilterValues