|
- Sub ek_sky()
- Dim ar1 As Variant, ar2 As Variant
- Dim ro1 As Object
- Dim i As Long, j As Long, k As Long
- Set ro1 = CreateObject("scripting.dictionary")
- With Sheets("导出数据")
- ar1 = .Range("A3:I" & .Cells(.Rows.Count, 1).End(xlUp).Row)
- End With
- ReDim ar2(1 To UBound(ar1), 1 To 16)
- For i = 1 To UBound(ar1)
- If Not ro1.exists(ar1(i, 4)) Then
- j = j + 1
- ro1.Add ar1(i, 4), j
- ar2(j, 1) = ar1(i, 4): ar2(j, Month(ar1(i, 1)) + 1) = ar1(i, 8)
- ar2(j, 15) = ar1(i, 9): ar2(j, 16) = ar1(i, 8)
- Else
- ar2(ro1(ar1(i, 4)), Month(ar1(i, 1)) + 1) = ar1(i, 8) + ar2(ro1(ar1(i, 4)), Month(ar1(i, 1)) + 1)
- ar2(ro1(ar1(i, 4)), 15) = ar1(i, 9) + ar2(ro1(ar1(i, 4)), 15)
- ar2(ro1(ar1(i, 4)), 16) = ar1(i, 9) + ar2(ro1(ar1(i, 4)), 16)
- End If
- Next i
- For k = 1 To j
- ar2(k, 14) = Round(ar2(k, 15) / ar2(k, 16), 4)
- Next k
- Sheets("sheet1").Select
- Range("A:O").Clear
- Range("A1:O1") = Array("商品编码", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月", "平均单价", "总金额")
- Range("A2").Resize(j, 15) = ar2
- End Sub
复制代码 |
|