|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
短信收到,请测试
Sub Macro1()
Dim arr, t, d As Object, i&, j&, m&
Set d = CreateObject("scripting.dictionary")
arr = Range("A1").CurrentRegion
For i = 2 To UBound(arr)
d(arr(i, 1) & arr(i, 2) & arr(i, 3) & arr(i, 4)) = i
Next
t = d.items
For i = 0 To d.Count - 1
m = i + 2
For j = 1 To 6
arr(m, j) = arr(t(i), j)
Next
Next
ActiveSheet.UsedRange.ClearContents
Range("A1").Resize(m, 6) = arr
End Sub
或
Sub Macro2() '写到Sheet2
Dim arr, t, d As Object, i&, j&, m&
Set d = CreateObject("scripting.dictionary")
arr = Range("A1").CurrentRegion
For i = 2 To UBound(arr)
d(arr(i, 1) & arr(i, 2) & arr(i, 3) & arr(i, 4)) = i
Next
t = d.items
For i = 0 To d.Count - 1
m = i + 2
For j = 1 To 6
arr(m, j) = arr(t(i), j)
Next
Next
With Sheets("Sheet2")
.UsedRange.ClearContents
.Range("A1").Resize(m, 6) = arr
End With
End Sub
|
|