1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| Sub 字典查询()
Dim i, j, k, irow
Dim cel As Range
Dim t As Double
t = Timer
Sheets("查询").Range("a6:d65536").ClearContents
Dim str As String
str = Sheets("查询").Range("b3")
Dim ar, br() 'ar 数据源 ,br 结果
With Sheets("数据源")
irow = .[a65536].End(3).Row
ar = .Range("a2:d" & irow)
End With
Dim d As Object, kw$
Set d = CreateObject("Scripting.Dictionary")
'd.CompareMode = vbTextCompare '不区分大小写
For i = 1 To UBound(ar)
'If InStr(ar(i, 1), str) > 0 Then
If ar(i, 1) Like "*" & str & "*" Then
If Not d.exists(str) Then
d(str) = i
Else
d(str) = d(str) & "," & i
End If
End If
Next i
Dim tmpAr
tmpAr = Split(d(str), ",")
ReDim br(1 To UBound(tmpAr) + 1, 1 To UBound(ar, 2))
For i = 0 To UBound(tmpAr)
For j = 1 To UBound(ar, 2)
br(i + 1, j) = ar(tmpAr(i), j)
Next j
Next i
Sheets("查询").Range("a6").Resize(UBound(br), UBound(br, 2)) = br
MsgBox Format(Timer - t, "0.000s")
End Sub
|