我需要以下帮助
我的代码将转到列的末尾,然后在下面的行中对该列内的数据进行求和。我想将该公式拖到剩余的活动列中。而不必手动重写每列的代码。
这是我挣扎的最后一行代码
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