|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub Macro1()
Dim arr, brr, crr, d As Object, i&, j&
Set d = CreateObject("scripting.dictionary")
arr = Range("a1").CurrentRegion '原始数据
For i = 2 To UBound(arr)
Set d(arr(i, 1)) = CreateObject("scripting.dictionary") '设置字典嵌套
Next
For i = 2 To UBound(arr)
For j = 2 To UBound(arr, 2)
d(arr(i, 1))(arr(1, j)) = d(arr(i, 1))(arr(1, j)) + arr(i, j)
Next
Next
Range("a15") = "店名/月份"
Range("a16").Resize(d.Count, 1) = Application.Transpose(d.Keys)
Range("b15").Resize(1, d(arr(i - 1, 1)).Count) = d(arr(i - 1, 1)).Keys
brr = Range("a15").CurrentRegion '目标数据
ReDim crr(1 To UBound(brr) - 1, 1 To UBound(brr, 2) - 1)
For i = 2 To UBound(brr)
For j = 2 To UBound(brr, 2)
crr(i - 1, j - 1) = d(brr(i, 1))(brr(1, j))
Next
Next
Range("b16").Resize(UBound(crr), UBound(crr, 2)) = crr
End Sub
|
|