#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default SUM in VBA

I would like to insert into a macro an instruction to insert the formula that
sums all the cells (in the existing column) from row 3 to the row just above
the cell with the SUM formula.
I have tried the following without success (generates a VBA error):

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

If someone could help, I would be most grateful.
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default SUM in VBA

Hi Steve,

Try:

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


---
Regards,
Norman



"Steve Pollack" wrote in message
...
I would like to insert into a macro an instruction to insert the formula
that
sums all the cells (in the existing column) from row 3 to the row just
above
the cell with the SUM formula.
I have tried the following without success (generates a VBA error):

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

If someone could help, I would be most grateful.
Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default SUM in VBA

Hi,

and would like to use instead of the numbers 3 or -1 variables, but it
doesn't work.
e.g.

ActiveCell.FormulaR1C1 = "=SUM(R[varRow]C:R[varRow2]C)"

what should I do?
--
Thank you very much

PeterS


"Norman Jones" wrote:

Hi Steve,

Try:

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


---
Regards,
Norman



"Steve Pollack" wrote in message
...
I would like to insert into a macro an instruction to insert the formula
that
sums all the cells (in the existing column) from row 3 to the row just
above
the cell with the SUM formula.
I have tried the following without success (generates a VBA error):

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

If someone could help, I would be most grateful.
Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default SUM in VBA

Hi Peter,

Try something like:

'=============
Public Sub Tester()
Dim varRow As Long
Dim varRow2 As Long

varRow = 3
varRow2 = 9

ActiveCell.FormulaR1C1 = _
"=SUM(R" & varRow & "C:R" & varRow2 & "C)"

End Sub
'<<=============



---
Regards,
Norman


"PeterS" wrote in message
...
Hi,

and would like to use instead of the numbers 3 or -1 variables, but it
doesn't work.
e.g.

ActiveCell.FormulaR1C1 = "=SUM(R[varRow]C:R[varRow2]C)"

what should I do?
--
Thank you very much

PeterS



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



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