|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 筛选()
Application.ScreenUpdating = False
Dim ar As Variant, cr As Variant
Dim i As Long, r As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("需求品目")
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:a" & r)
End With
For i = 1 To UBound(ar)
If ar(i, 1) <> "" Then
d(ar(i, 1)) = ""
End If
Next i
With Sheets("Sheet1")
cr = .[a1].CurrentRegion
End With
ReDim br(1 To UBound(cr), 1 To UBound(cr, 2))
For i = 2 To UBound(cr)
If cr(i, 3) <> "" Then
If d.exists(cr(i, 3)) Then
n = n + 1
For j = 1 To UBound(cr, 2)
br(n, j) = cr(i, j)
Next j
End If
End If
Next i
If n = "" Then MsgBox "没有符合条件的数据!": End
With Sheets("筛选结果")
.[a1].CurrentRegion = Empty
.[a1].Resize(1, UBound(cr, 2)) = cr
.[a2].Resize(n, UBound(br, 2)) = br
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|