how to set current cell (variable row) to sum values of all cells above

E

Eric Bragas

Hi,

I need to sum the values of all cells above my current cell, but my
current row changes with each spreadsheet. I recorded a macro and got
the following code:

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

But the problem is the "-17". In this case I was on row 18--I think--
but next time I'll be on a different row, so this macro won't work.

How do I sum all cells from the cell above my current cell to the top
row?

Thanks,
Eric
 
M

merjet

Sub Sums()
Dim iEnd As Integer
Dim iCol As Integer
iCol = ActiveCell.Column
iEnd = Cells(1, iCol).End(xlDown).Row
Cells(iEnd + 1, iCol).Formula = "=SUM(" & Cells(1, iCol).Address _
& ":" & Cells(iEnd, iCol).Address & ")"
End Sub

Hth,
Merjet
 

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