数据大致如725楼
我的代码如下:
Sub 统计数据() Dim sum1, sum2, sum3, sum4, ix, iy, xy As Integer sum1 = Sheets(ActiveSheet.Name).[a1].CurrentRegion.Rows.Count '上面一行可以自动获取当前表格的行数 sum2 = Sheets(ActiveSheet.Name).[a1].CurrentRegion.Columns.Count '上面一行可以自动获取当前表格的列数 For sum3 = 1 To Int(sum1 / 3) For sum4 = 3 To sum2 Cells(3 * sum3 + 1, sum4) = Cells(3 * sum3 - 1, sum4) * Cells(3 * sum3, sum4) Next Next '前面几行循环求出每三行的合计 xy = Int(sum1 / 3) For ix = 3 To sum2 k = 0 For iy = 1 To sum1 If iy Mod 3 = 0 Then k = k + Cells(iy + 1, ix) Cells(sum1, ix) = k End If Next Next '这里几行循环求出月销售总额 End Sub '整个代码可以自动计算出月销售总额和各商品的合计。 '数据有增加这几行就够了。加多少都可以自动计算出来
|