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
| 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() With Sheets("数据源") irow = .[a65536].End(3).Row ar = .Range("a2:d" & irow) End With
Dim d As Object, kw$ Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(ar) If Not d.exists(ar(i, 1)) Then d(ar(i, 1)) = i Else d(ar(i, 1)) = d(ar(i, 1)) & "," & i 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
|