|
参与一下。
使用排序加二分法,一秒内完成。
不过好像能配上的数据不多。
- Sub tt()
-
- Dim Arr, Brr
- Dim i&, j&, T$, x&, y&, N&
- Dim t1, t2
- t1 = Timer
-
- With Sheets("1")
- j = .Cells(Rows.Count, 1).End(xlUp).Row
- Arr = .Range("a2:c" & j)
- End With
-
- With Sheets("2")
- .Activate
- i = .Cells(Rows.Count, 1).End(xlUp).Row
- .Range("a1:b" & i).Sort key1:=[a1], Order1:=1, Header:=xlYes
- Brr = .Range("a2:b" & i)
- End With
-
- For i = 1 To UBound(Arr)
- T = Arr(i, 1)
- x = LBound(Brr)
- y = UBound(Brr)
- Do
- N = (x + y) / 2
- If Brr(N, 1) < T Then
- x = N + 1
- ElseIf Brr(N, 1) > T Then
- y = N - 1
- Else
- Arr(i, 3) = Brr(N, 2)
- Exit Do
- End If
- Loop While x <= y
- Next i
-
- With Sheets("1")
- .Activate
- .Range("a2:c" & j) = Arr
- End With
-
- t2 = Timer
- MsgBox t2 - t1
-
- End Sub
复制代码 |
|