Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default using Formulas in VBA

I need to be able to add the sum of a column of data into the cell at the
bottom of the column. I can do this using

ActiveCell.FormulaR1C1 = "=SUM(R[-121)]C:R[-1]C)"


However this number of rows in the column may vary so I cannot use a
pre-defined R1C1 range in the formula. Each time the code is run the number
of rows may be more or less so the -121 will vary.

How can I overcome this please?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default using Formulas in VBA

This will calculate the last used row in column A and put the formula in the
next row

Dim iLastRow As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).row
Cells(iLastRow + 1, "A").FormulaR1C1 = "=SUM(R[-" & iLastRow &
"]C:R[-1]C)"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alan M" wrote in message
...
I need to be able to add the sum of a column of data into the cell at the
bottom of the column. I can do this using

ActiveCell.FormulaR1C1 = "=SUM(R[-121)]C:R[-1]C)"


However this number of rows in the column may vary so I cannot use a
pre-defined R1C1 range in the formula. Each time the code is run the

number
of rows may be more or less so the -121 will vary.

How can I overcome this please?



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
Convert Array Formulas to Regular Formulas minyeh Excel Worksheet Functions 0 March 21st 10 05:55 AM
E2007 formulas display as formulas, not results Pierre Excel Worksheet Functions 3 January 14th 10 04:59 PM
Counting # of Formulas in a column with formulas and entered data Brand Excel Worksheet Functions 1 October 10th 09 01:01 PM
CELLS NOT CALC FORMULAS - VALUES STAY SME FORMULAS CORRECT?? HELP Sherberg Excel Worksheet Functions 4 September 11th 07 01:34 AM
AdvancedFilter on cells with formulas, returning values and not formulas Claus[_3_] Excel Programming 2 September 7th 05 02:40 PM


All times are GMT +1. The time now is 08:20 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"