Selection.End(xlDown).Select
Range("L108").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-106]C:R[-1]C)"
Range("L108").Select
Selection.Copy
Range("L108:N108").Select
Application.CutCopyMode = False
Selection.FillRight
需要在L,M和N列下添加和函数,以便能够适应其中行数将改变的其他电子表格,因此总和不会是相同的范围
答案 0 :(得分:1)
这将找到底部值(示例代码中的第107行),并在列L,M和N的下一行(样本中的第108行)中输入SUM公式。
dim lr as long
with worksheets("sheet1")
lr = .cells(.rows.count, "L").end(xlup).row
.cells(lr + 1, "L").resize(1, 3).formular1c1 = _
"=sum(r2c:r" & lr & "c)"
end with
答案 1 :(得分:1)
以下内容将在 B 列中的最后一个单元格下方插入公式:
Sub MakeColumnSum()
Dim kolumn As String, where As Range
kolumn = "B"
Set where = Range(kolumn & Rows.Count).End(xlUp).Offset(1, 0)
where.Formula = "=SUM(" & kolumn & "1:" & kolumn & where.Row - 1 & ")"
End Sub