Sub 测试() ''答题专用套路--by:学习使我快乐
Dim i, j, k, m, n, arr, brr, crr, drr
Dim sht As Worksheet, wbk As Workbook, rng As Range
Dim dic As Object, key As String, keys, items
Set dic = CreateObject("scripting.dictionary")
arr = Sheet1.Range("A1:D" & Sheet1.Cells(Rows.Count, "B").End(xlUp).Row)
ReDim brr(1 To 3)
For i = 2 To UBound(arr)
key = arr(i, 2)
If Not dic.Exists(key) Then
k = 1
brr(1) = arr(i, 2)
brr(3) = arr(i, 4)
dic(key) = brr
Else
brr = dic(key)
k = k + 1
brr(1) = arr(i, 2) & "(" & k & "笔)"
brr(3) = brr(3) + arr(i, 4)
dic(key) = brr
End If
Next
keys = dic.keys
ReDim crr(1 To dic.Count, 1 To 3)
For i = LBound(keys) To UBound(keys)
key = keys(i)
brr = dic(key)
For j = 1 To 3
crr(i + 1, j) = brr(j)
Next
Next
Sheet1.Range("I8").Resize(UBound(crr), UBound(crr, 2)) = crr
End Sub |