ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SUM in VBA (https://www.excelbanter.com/excel-programming/386637-sum-vba.html)

Steve Pollack

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.

Norman Jones

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.




Peters

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.





Norman Jones

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





All times are GMT +1. The time now is 07:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com