|
楼主 |
发表于 2018-9-30 12:18
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 ericniming 于 2018-9-30 13:31 编辑
嗯,是很少有这个要求。因为需要加和的sheet有几十个,每次范围不一样,用excel公式做很麻烦。后来我用循环赋值搞定了。
Private Sub CommandButton1_Click()
Dim beg, fin As String, i, j, k, m, n, o, p, q As Integer
beg = [b1]
m = [b2]
fin = [b5]
n = [b6]
o = Worksheets.Count
p = n - m + 1
q = Cells(n, fin).Column - Cells(m, beg).Column + 1
ReDim brr(1 To p, 1 To q), crr(1 To p, 1 To q) As Variant
For k = 3 To o
For i = 1 To p
For j = 1 To q
brr(i, j) = Sheets(k).Cells(m, beg).Offset(i - 1, j - 1)
crr(i, j) = crr(i, j) + brr(i, j)
Next j
Next i
Next k
Sheets(2).UsedRange.Clear
Sheets(2).Cells(m, beg).Resize(p, q) = crr
Sheets(2).Activate
End Sub
|
|