|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 Vicel 于 2016-11-20 21:35 编辑
刚才的代码有误,更正一下
Sub test()
Dim ar, br(), d As Object, i&, j&, n&
t = Timer
Set d = CreateObject("scripting.dictionary")
ar = Sheets("数据").[A1].CurrentRegion
ReDim br(1 To UBound(ar), 1 To 3)
For i = 2 To UBound(ar)
If Not d.exists(ar(i, 1)) Then
d(ar(i, 1)) = i
Else
If InStr(d(ar(i, 1)), ",") = 0 Then
n = n + 1
d(n) = ar(i, 1)
End If
d(ar(i, 1)) = d(ar(i, 1)) & "," & i
End If
Next i
For i = 1 To n
br(i, 3) = d(d(i))
br(i, 1) = d(i)
ar = Split(br(i, 3), ",")
br(i, 2) = UBound(ar) + 1
Next i
[I2].Resize(n, 3) = br
Set d = Nothing
MsgBox Timer - t
End Sub
|
|