回家重新写了一个,代码如下,手机码字,格式可能不太对Sub 分类汇总()
Dim rng As Range, arr, i As Integer
arr = ActiveSheet.Range(Range("a1"), Cells(Rows.Count, 3).End(xlUp)).Value
Application.DisplayAlerts = False
On Error Resume Next
With CreateObject("scripting.dictionary")
For i = 1 To UBound(arr)
If Len(arr(i, 2)) > 0 Then
.Item(CStr(arr(i, 1) & "/" & arr(i, 2))) = .Item(CStr(arr(i, 1) & "/" & arr(i, 2))) + arr(i, 3)
End If
Next i
Set rng = Application.InputBox("请选择数据存放区域", "指定区域", , , , , , 8)
If Err <> 0 Then Exit Sub
'对输出数据部分清零
' rng(1).Offset(0, 3).EntireColumn.Clear
rng(1).Resize(.Count, 1) = WorksheetFunction.Transpose(.keys)
'对数据分列
rng(1).CurrentRegion.TextToColumns Destination:=rng(1), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="/", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
rng(1).Offset(0, 2).Resize(.Count, 1) =WorksheetFunction.Transpose(.items)
rng(1).CurrentRegion.Borders.LineStyle = 1
Application.DisplayAlerts = True
End With
End Sub |