Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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)"

  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Macro code to autosum a dynamic length column

How about

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

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"SlowPoke" wrote in message
ups.com...
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)"



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

It gives a compile error on compile pointing to M2 "Expected end of
statement"

  #4   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default Macro code to autosum a dynamic length column

Sorry, my typo

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

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"SlowPoke" wrote in message
oups.com...
It gives a compile error on compile pointing to M2 "Expected end of
statement"



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import a Code to a paragraph using a formula or macro! Manos Excel Worksheet Functions 3 February 11th 06 07:48 AM
Return SEARCHED Column Number of Numeric Label and Value Sam via OfficeKB.com Excel Worksheet Functions 23 January 30th 06 06:16 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Zip Code Macro Ken Wright Excel Worksheet Functions 0 December 9th 04 07:55 AM


All times are GMT +1. The time now is 03:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"