我有一个有23列和不同行数的数据集。我需要根据一组条件(包括通配符)自动筛选数据,然后将过滤后的结果复制粘贴到相应的工作表中(即,带有过滤标准SH00 * 的数据应放入表SH00中-表的名称与标准相同,但不带通配符)。要过滤的数据位于第I列。这是我目前掌握的情况:
Sub Filter_Data()
Sheets("Blokkeringen").Select
'Filter
Dim dic As Object
Dim element As Variant
Dim criteria As Variant
Dim arrData As Variant
Dim arr As Variant
Set dic = CreateObject("Scripting.Dictionary")
arr = Array("SH00*", "SH0A*", "SH0B*", "SH0D*", "SH0E*", "SH0F*", "SH0H*", "SHA*", "SHB*", "SF0*")
With ActiveSheet
.AutoFilterMode = False
arrData = .Range("I1:I" & .Cells(.Rows.Count, "I").End(xlUp).Row)
For Each criteria In arr
For Each element In arrData
If element Like criteria Then dic(element) = vbNullString
Next
Next
.Columns("I:I").AutoFilter Field:=1, Criteria1:=dic.keys, Operator:=xlFilterValues
End With
'Copypaste
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("SH00").Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
Cells(1, 1).Select
Sheets("Blokkeringen").AutoFilterMode = False
Application.CutCopyMode = False
Sheets("Blokkeringen").Select
Cells(1, 1).Select
End Sub
这段代码基于条件+通配符进行过滤,但同时应用所有过滤器。它还将整个结果复制粘贴到第一个工作表中。我完全搞不懂的是如何同时循环过滤和复制粘贴过程。
任何帮助都将不胜感激。
1条答案
按热度按时间dl5txlt91#
将过滤的数据导出到工作表