View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
SlowPoke
 
Posts: n/a
Default Macro code to autosum a dynamic length column

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,COU NT(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)"