|
- Sub tt()
- Set d1 = CreateObject("scripting.dictionary") '供方
- Set d2 = CreateObject("scripting.dictionary") '供方全,用以计算实数(全)
- Set d3 = CreateObject("scripting.dictionary") '供方全,用以计算工合计(全)
- r = Sheet1.[a65536].End(3).Row
- arr = Sheet1.Range("a5:r" & r)
- For i = 1 To UBound(arr)
- d1(arr(i, 2)) = ""
- d2(arr(i, 2) & arr(i, 18)) = d2(arr(i, 2) & arr(i, 18)) + arr(i, 9) '供方+方式,“实数”累加
- d3(arr(i, 2) & arr(i, 18)) = d3(arr(i, 2) & arr(i, 18)) + arr(i, 17) '供方+方式,“工合计”累加
- Next
- brr = d1.keys
- keyd2 = d2.keys: itemd2 = d2.items
- itemd3 = d3.items
- Set sh = Sheet1
- With Sheet3
- .Range("a3:O100").ClearContents
- Dim crr(1 To 15) '汇总每行(共15列)
- For i = 0 To UBound(brr)
- crr(13) = 0: crr(14) = 0: crr(15) = 0 '由于并不是所有供方都有“全”方式,因此第13、14、15列赋初值0
- xr = i + 3 '所要填的行
- crr(1) = i + 1 '序号
- crr(2) = brr(i) '供方
- For j = 3 To 12 '标数、实数。。。。。。。、工合计
- crr(j) = Application.SumIf(sh.Range("b5:b" & r), brr(i), sh.Range(sh.Cells(5, j + 5), sh.Cells(r, j + 5)))
- Next
- For k = 0 To UBound(keyd2)
- If keyd2(k) = brr(i) & "全" Then '如果条件为“供方全”,得到“实数”、“工合计”、“方式”
- crr(13) = itemd2(k)
- crr(14) = itemd3(k)
- If crr(13) <> 0 Then crr(15) = Format(crr(14) / crr(13), "0.00%")
- End If
- Next
- .Cells(xr, 1).Resize(1, 15) = crr '填充
- Next
- .Range("B3:O" & xr).Sort Key1:=.Range("B3"), Order1:=xlAscending '按供方排序
- End With
- End Sub
复制代码 见附件,体现在Sheet3里 |
评分
-
1
查看全部评分
-
|