0

id like help with the below

my code is going to the end of a column, then in the row below is summing the data within the column. I want to drag that formula across the remaining active columns. with out having to rewrite the code for each column manually.

its my last line of code i am struggling with

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
  • Although this is an Excel problem, it's essentially a code problem, so it might you might have more success asking this on Stack Overflow. Make sure to reference each question if you cross post (include a link to the other questions in your posts, if you put the same question on more then one site).
    – Albin
    Aug 1, 2019 at 6:50

1 Answer 1

0
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .