Macro code to autosum a dynamic length column

  • Thread starter Thread starter SlowPoke
  • Start date Start date
S

SlowPoke

I have a macro where I want to get some totals of a couple columns. I
have the row number in a variable where I will put the totals, but
cannot figure out how to do the autosum. Here is the code I am trying
to get working. nRow is the row for the totals. I want to total
columns M and N from row 2 to nRow. I would appreciate some help in
this.

nRow = nRow + 2
Cells(nRow, 1) = "Totals"
' Range(nRow).Select
' ActiveCell.FormulaR1C1 = "Totals"
Range("M2:M" & nRow).Select
' cells(nRow,13)
ActiveCell.FormulaR1C1 =
"=SUM(M2:M7,(IF(COUNT(M9:M990)>0,OFFSET(M9,0,0,COUNT(M9:M990)),0)))"

' ActiveCell.FormulaR1C1 = "=SUM(M2:MR[-1]C)"
' Range("N2:N26").Select
' Range("N26").Activate
' ActiveCell.FormulaR1C1 = "=SUM(R[-24]C:R[-1]C)"
 
How about

Cells(nRow,"M").Formula = "=SUM("M2:M" & nRow - 1 & ")"

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
Sorry, my typo

Cells(nRow,"M").Formula = "=SUM(M2:M" & nRow - 1 & ")"

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top