|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 cui26896 于 2020-10-17 15:52 编辑
Sub test()
Dim arr, brr, d, d2, i%, j%, j2%, k, k2, s
Set d = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
arr = Sheets(1).Range("a1:d" & Sheets(1).UsedRange.Rows.Count)
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
For i = 2 To UBound(arr)
s = vbNullString
For j = 1 To UBound(arr, 2)
If j < UBound(arr, 2) Then
s = s & arr(i, j) & "|"
Else
s = s & arr(i, j)
End If
Next
If arr(i, 1) <> "……" And Not d.exists(s) Then
k = k + 1
d(s) = k
For j = 1 To UBound(arr, 2)
brr(d(s), j) = arr(i, j)
Next
End If
Next
ReDim arr(1 To k, 1 To UBound(brr, 2))
For i = 1 To k
s = vbNullString
For j = 1 To UBound(brr, 2)
If j < UBound(brr, 2) - 1 Then
s = s & brr(i, j) & "|"
Else
s = s & brr(i, j)
End If
Next
If d2.exists(s) = False Then
k2 = k2 + 1
d2(s) = k2
For j2 = 1 To UBound(brr, 2)
arr(d2(s), j2) = brr(i, j2)
Next
Else
arr(d2(s), 4) = arr(d2(s), 4) + brr(i, 4)
End If
Next
With Sheets(1)
.Range("o2").Resize(k2+1, UBound(arr, 2)) = arr
.Range("o2:r" & k2+1).Sort key1:=.Range("q2"), order1:=xlAscending, Header:=xlNo
.Range("o2:r" & k2+1).Sort key1:=.Range("p2"), order1:=xlAscending, Header:=xlNo
.Range("o2:r" & k2+1).Sort key1:=.Range("o2"), order1:=xlAscending, Header:=xlNo
End With
End Sub
|
|