Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default how to set current cell (variable row) to sum values of all cells above

Thanks, Merjet, your suggest works perfectly!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
change cell values of to reflect most current entry in a range MARYINNEED Excel Worksheet Functions 3 April 13th 08 06:52 PM
Replacing Linked Cell Values w/ Current Values TomCat Excel Worksheet Functions 6 April 10th 06 12:20 PM
Populating a cell with the current value of a variable Linking to specific cells in pivot table Excel Programming 1 May 18th 05 10:29 AM
variable = current cell in VB Tim Excel Programming 5 February 24th 04 03:17 PM
Convert to values, but not at current cell Bruce Roberson Excel Programming 1 August 27th 03 10:15 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"