|
这样行不行
- Sub test()
- Dim Dic(1 To 3) As Object, i&, j&, tmpStr$, Arr
- Arr = Sheet1.[a1].CurrentRegion
- For i = 1 To UBound(Dic)
- Set Dic(i) = CreateObject("scripting.dictionary")
- Dic(i).comparemode = vbTextCompare
- Next i
- For i = 2 To UBound(Arr, 1)
- Dic(1)(Arr(i, 1)) = ""
- Dic(2)(Arr(i, 2)) = ""
- tmpStr = Arr(i, 1) & Chr(10) & Arr(i, 2)
- Dic(3)(tmpStr) = Dic(3)(tmpStr) + Arr(i, 3)
- Next i
- ReDim brr(1 To Dic(2).Count + 1, 1 To Dic(1).Count + 1)
- '分布行标
- brr(1, 1) = "汇总"
- i = 1
- For Each k In Dic(2).keys
- i = i + 1
- brr(i, 1) = k
- Next k
- '分布列标
- j = 1
- For Each k In Dic(1).keys
- j = j + 1
- brr(1, j) = k
- Next k
- For i = 2 To UBound(brr, 1)
- For j = 2 To UBound(brr, 2)
- brr(i, j) = Dic(3)(brr(1, j) & Chr(10) & brr(i, 1))
- Next j
- Next i
- With Sheet1 '返回结果
- j = .UsedRange.Columns.Count
- If j > 3 Then .[d1].Resize(1, j - 3).EntireColumn.ClearContents
- .[f1].Resize(UBound(brr, 1), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|