![将公式拖到最后一行已求和的活动列上 +1](https://linux22.com/image/1599054/%E5%B0%86%E5%85%AC%E5%BC%8F%E6%8B%96%E5%88%B0%E6%9C%80%E5%90%8E%E4%B8%80%E8%A1%8C%E5%B7%B2%E6%B1%82%E5%92%8C%E7%9A%84%E6%B4%BB%E5%8A%A8%E5%88%97%E4%B8%8A%20%2B1.png)
我需要以下帮助
我的代码将转到列的末尾,然后在下面的行中对该列内的数据进行求和。我想将该公式拖到剩余的活动列中。而不必手动重写每列的代码。
这是我挣扎的最后一行代码
Dim LR As Long
LR = Range("M" & Rows.Count).End(xlUp).Row
Range("M" & LR + 1).Formula = "=SUM(m7:M" & LR & ")"
Range("M" & LR + 1).Font.Bold = True
**Selection.AutoFill Destination:=Range("M" & LR + 1, lastcolumn), Type:=xlFillDefault**
答案1
Sub SetSums()
Dim sh As Worksheet
Set sh = ActiveSheet
Dim UpperCell As Range
' Iterate over upper cells of columns in question, multi-range used '
For Each UpperCell In sh.Range("A1:B1,C3,D1:E1")
UpperCell.EntireColumn.End(xlDown).Offset(1, 0).Formula = "=SUM(" & UpperCell.Address & ":" & UpperCell.EntireColumn.End(xlDown).Address & ")"
Next
End Sub