|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Option Explicit
- Sub test() 'http://club.excelhome.net/thread-1433441-1-1.html
- Dim Ar, I&, Br, K&, Dic, J&
- Set Dic = CreateObject("Scripting.Dictionary")
- Ar = Sheets("sheet1").Range("a1:e" & Cells(Rows.Count, 5).End(3).Row)
- ReDim Br(1 To UBound(Ar), 1 To 3)
- For I = 2 To UBound(Ar)
- If Ar(I, 5) <> "" Then
- If Dic(Ar(I, 5)) = "" Then
- K = K + 1
- Dic(Ar(I, 5)) = K
- Br(K, 1) = Ar(I, 5)
- End If
- Br(Dic(Ar(I, 5)), 2) = Br(Dic(Ar(I, 5)), 2) + Ar(I, 2)
- Br(Dic(Ar(I, 5)), 3) = Br(Dic(Ar(I, 5)), 3) + Ar(I, 4)
- End If
- Next I
- 'Stop
- Sheets("sheet1").Range("g1").CurrentRegion.ClearContents
- Sheets("sheet1").Range("h1") = Ar(1, 2)
- Sheets("sheet1").Range("i1") = Ar(1, 4)
- Sheets("sheet1").Range("g2").Resize(K, 3) = Br
- End Sub
- Sub test1() ' 第二步在原有位置上转转置
- Dim Ar
- Ar = Sheets("sheet1").Range("g1").CurrentRegion
- Sheets("sheet1").Range("g1").CurrentRegion.ClearContents
- Sheets("sheet1").Range("g1").Resize(UBound(Ar, 2), UBound(Ar)) = Application.WorksheetFunction.Transpose(Ar)
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|