|
Sub dic_mothod()
Dim brr(), crr()
'名称去重并加入字典
With Worksheets("数据源")
arr = .[a1].CurrentRegion.Value
title_arr = .[a1].CurrentRegion.Resize(1, UBound(arr, 2)).Value
End With
Set dic = CreateObject("scripting.dictionary")
dic_num = UBound(arr, 2)
ReDim brr(2 To dic_num), crr(2 To dic_num)
For irow = 2 To UBound(arr)
name_ = arr(irow, 1)
If Not dic.exists(name_) Then
dic(name_) = brr
End If
Next
'对应的名字下累计做过的事情
For irow = 2 To UBound(arr, 1)
name_ = arr(irow, 1)
end_ = UBound(dic(name_))
For i = 2 To end_ - 1
crr(i) = dic(name_)(i) & arr(irow, i) '累计文字
Next
crr(end_) = dic(name_)(end_) + arr(irow, end_) '累计数字
dic(name_) = crr
Next
'打印
With Worksheets("结果")
.[a:h].Clear
.[a1].Resize(1, UBound(arr, 2)) = title_arr
.[a1].Resize(1, UBound(arr, 2)).Style = "title" '新建单元格样式,并命名为 title。懒得写代码
irow = 2
For Each k In dic.keys
.Rows(irow).RowHeight = 75 '行宽统一为75。比较输入
.Cells(irow, 1) = k
.Cells(irow, 1).Style = "结果"
.Cells(irow, 2).Resize(1, UBound(arr, 2) - 1) = dic(k)
.Cells(irow, 2).Resize(1, UBound(arr, 2) - 1).Style = "结果" '新建单元格样式,并命名为 结果。懒得写代码
irow = irow + 1
Next
.[a:h].EntireColumn.AutoFit '自动列宽
End With
End Sub
附件直接能用了。我已经设置好单元格样式。 |
|