Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
hal hal is offline
external usenet poster
 
Posts: 2
Default Whats wrong with this VBA statement -ActiveCell.FormulaR1C1...?

ActiveCell.FormulaR1C1 = "=SUM(R[-(Range("j1").Value)]C:R[-1]C)"

I am trying to put a formula in the active cell to sum a list of numbers starting from 1 row up, to the number of rows up that is equal to the value in the cell j1. In other word if the value in the cell j1 was 9, I need to sum from 1 row up to 9 rows up.

Thank you in advance for any help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Whats wrong with this VBA statement -ActiveCell.FormulaR1C1...?

Activecell.value="=Sum(R" & Range("J1").value & ":R9)"
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Whats wrong with this VBA statement -ActiveCell.FormulaR1C1...?

Try

ActiveCell.FormulaR1C1 = "=SUM(R[-" & Range("j1").Value & "]C:R[-1]C)"


--
Darren

"hal" wrote in message
...
ActiveCell.FormulaR1C1 = "=SUM(R[-(Range("j1").Value)]C:R[-1]C)"

I am trying to put a formula in the active cell to sum a list of numbers

starting from 1 row up, to the number of rows up that is equal to the value
in the cell j1. In other word if the value in the cell j1 was 9, I need to
sum from 1 row up to 9 rows up.

Thank you in advance for any help.



  #4   Report Post  
Posted to microsoft.public.excel.programming
hal hal is offline
external usenet poster
 
Posts: 2
Default Whats wrong with this VBA statement -ActiveCell.FormulaR1C1...?

Thanks for your help, works great!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Whats wrong with this VBA statement -ActiveCell.FormulaR1C1...?

If it were not for the need to double the quotes, the formula that would end up in the cell
would be

=SUM(R[-(Range("j1").Value)]C:R[-1]C)

which of course makes no sense on the worksheet -- it doesn't know anything about Range and
Value and ranges in quotes.

For easier reading and debugging, I usually construct these kinds of formulas with placeholders,
then, use Replace to fill in the variable pieces:

Dim sFormula As String

sFormula = "=SUM(R[-###]C:R[-1]C)"
sFormula = Replace(sFormula, "###", Range("J1").Value)
ActiveCell.FormulaR1C1 = sFormula

If there are multiple variable to be replaced, be sure to use unique placeholders for each, i.e.
###, $$$, @@@, ^^^, XX1, XX2, XX3, XY1, etc.

On Fri, 7 Nov 2003 17:36:08 -0800, hal wrote:

ActiveCell.FormulaR1C1 = "=SUM(R[-(Range("j1").Value)]C:R[-1]C)"

I am trying to put a formula in the active cell to sum a list of numbers starting from 1 row

up, to the number of rows up that is equal to the value in the cell j1. In other word if the
value in the cell j1 was 9, I need to sum from 1 row up to 9 rows up.

Thank you in advance for any help.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Whats wrong with this VBA statement -ActiveCell.FormulaR1C1...?

I'm not the one who asked the question, but this technique is going to be
very handy for me on my current spreadsheet, so Thanks! :)

--
Darren

"Myrna Larson" wrote in message
...
If it were not for the need to double the quotes, the formula that would

end up in the cell
would be

=SUM(R[-(Range("j1").Value)]C:R[-1]C)

which of course makes no sense on the worksheet -- it doesn't know

anything about Range and
Value and ranges in quotes.

For easier reading and debugging, I usually construct these kinds of

formulas with placeholders,
then, use Replace to fill in the variable pieces:

Dim sFormula As String

sFormula = "=SUM(R[-###]C:R[-1]C)"
sFormula = Replace(sFormula, "###", Range("J1").Value)
ActiveCell.FormulaR1C1 = sFormula

If there are multiple variable to be replaced, be sure to use unique

placeholders for each, i.e.
###, $$$, @@@, ^^^, XX1, XX2, XX3, XY1, etc.

On Fri, 7 Nov 2003 17:36:08 -0800, hal

wrote:

ActiveCell.FormulaR1C1 = "=SUM(R[-(Range("j1").Value)]C:R[-1]C)"

I am trying to put a formula in the active cell to sum a list of numbers

starting from 1 row
up, to the number of rows up that is equal to the value in the cell j1. In

other word if the
value in the cell j1 was 9, I need to sum from 1 row up to 9 rows up.

Thank you in advance for any help.




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
ActiveCell.FormulaR1C1 Rick Excel Discussion (Misc queries) 3 March 28th 10 10:36 PM
ActiveCell.FormulaR1C1 = "=SUM(R[-tellerteller]C:R[-1]C)" Jack Sons Excel Discussion (Misc queries) 5 September 29th 09 09:58 PM
whats wrong with this? brownti via OfficeKB.com Excel Discussion (Misc queries) 10 February 12th 07 02:39 PM
Whats wrong with this? LucasBuck Excel Discussion (Misc queries) 3 January 12th 06 08:15 PM
ActiveCell.FormulaR1C1 Leif Rasmussen Excel Programming 1 October 16th 03 09:46 AM


All times are GMT +1. The time now is 09:23 AM.

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"