Simple Excel VBA question: How do I sum a range of cells?

  • Thread starter Thread starter Lazer
  • Start date Start date
L

Lazer

This is *bad* syntax:
Range("C" & currentOutputRow).Formula = Sum(Range("C"
firstRowContainingDataInOutputWorksheet, "C" & currentOutputRow - 1))

What is the proper syntax for summing a range?

Thanks!
Laze
 
Hi
what are you trying to achieve?
- Do you want to insert a formula in your cell
- do you want to sum a range and return the result to a variable in VBA
to further process this value
 
Would this work for you?

ActiveCell.FormulaR1C1 = "=Sum(R1C:R[-1]C)"
 
Range("C" & currentOutputRow).Formula = _
"=Sum(C" &
firstRowContainingDataInOutputWorksheet &
":C" & currentOutputRow - 1 & ")"
 

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

Back
Top