|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
使用数组、循环求和。试试看!- Sub Test()
- Dim arr, brr(), r&, c&, n&, m&
- arr = ActiveSheet.UsedRange
-
- For c = 5 To UBound(arr, 2) '外层循环列
- For r = 2 To UBound(arr) '内层循环行
- n = n + arr(r, c) '累加
- Next r
- ReDim Preserve brr(1 To UBound(arr, 2)) '定义动态数组存放每列累加的和
- m = m + 1 '累加
- brr(m) = n '将列累加的和赋值给数组
- n = 0 '计数器清空
- Next c
-
- Cells((UBound(arr) + 6), 1).Value = "合计"
- Cells((UBound(arr) + 6), 5).Resize(1, UBound(arr, 2)) = _
- Application.Transpose(Application.Transpose(brr))
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|