SUM in VBA

S

Steve Pollack

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.
 
P

PeterS

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 said:
Hi Steve,

Try:

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


---
Regards,
Norman



Steve Pollack said:
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.
 
N

Norman Jones

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
'<<=============
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top