|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 吴中泉 于 2023-3-27 08:57 编辑
在五楼VBA的基础上,进行了改进,速度提升了3倍.
- Sub lll()
- '关于多列提取每列重复数据
- Dim arr
- Dim arr1()
- Dim i, k, g As Integer
-
- 't = Timer
- arr = Range("a1").CurrentRegion
-
- For i = 1 To UBound(arr)
- m = 0
- For k = 1 To UBound(arr)
- If arr(i, 1) = arr(k, 2) Then
- m = m + 1: Exit For
- End If
- Next
- If m = 0 Then GoTo 循环尾
- For k = 1 To UBound(arr)
- If arr(i, 1) = arr(k, 3) Then
- m = m + 1: Exit For
- End If
- Next
- If m = 1 Then GoTo 循环尾
- For k = 1 To UBound(arr)
- If arr(i, 1) = arr(k, 4) Then
- m = m + 1: Exit For
- End If
- Next
- If m = 2 Then GoTo 循环尾
- g = g + 1
- ReDim Preserve arr1(1 To g)
- arr1(g) = arr(i, 1)
- 循环尾:
- Next
- Range("i2").Resize(UBound(arr1), 1) = Application.WorksheetFunction.Transpose(arr1)
- ' MsgBox Timer - t
- End Sub
复制代码
|
|