|
楼主 |
发表于 2023-3-30 21:20
|
显示全部楼层
已完美搞定,速度还很快,感谢原编者,提供了很好的算法和源程序
我感觉完美的代码如下,欢迎感兴趣的表哥表嫂们讨论交流。
- Option Explicit
- Sub Main()
- Dim d As Object, t
- Dim arr, c, i As Long, j As Long
- 't = Timer
- arr = ActiveSheet.Range("a1").CurrentRegion
- Set d = CreateObject("scripting.dictionary")
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = 0
- Next i
- 'Stop
- For j = 2 To UBound(arr, 2)
- For i = 1 To UBound(arr)
- If d.exists(arr(i, j)) Then
- d(arr(i, j)) = 1
- End If
- Next i
- For Each c In d.keys
- If d(c) < 1 Then
- d.Remove (c)
- Else
- d(c) = 0
- End If
- Next
- Next j
- 'Stop
- Range("f2").Resize(i, 1).Clear
- Range("f2").Resize(d.Count, 1) = Application.Transpose(d.keys)
- Erase arr
- Set d = Nothing
- 'MsgBox Timer - t
- End Sub
- '时间复杂度:O(n+n*列数)
复制代码 |
|