![]() |
how to set current cell (variable row) to sum values of all cells above
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 |
how to set current cell (variable row) to sum values of all cells above
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 |
how to set current cell (variable row) to sum values of all cells above
Thanks, Merjet, your suggest works perfectly!
|
All times are GMT +1. The time now is 01:39 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com