Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to Sum all values above


I need to write a macro that will sum all of the values above the
selected cell. Rows above cell are variable, so it has to be flexible.
Below is my code. I believe the sum formula will be where the *****
are. Any help would be appreciated. Thanks.

Range("E1").Select
Selection.End(xlDown).Select
ReportLastRow = ActiveCell.Row
ActiveCell.Offset(rowOffset:=1, columnoffset:=0).Activate
ActiveCell.FormulaR1C1 = _
"Total"
ActiveCell.Offset(rowOffset:=0, columnoffset:=1).Activate
ActiveCell.FormulaR1C1 = *****


--
mkerstei
------------------------------------------------------------------------
mkerstei's Profile: http://www.excelforum.com/member.php...o&userid=25688
View this thread: http://www.excelforum.com/showthread...hreadid=548761

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Need to Sum all values above

Assuming that the ActiveCell is at the blank cell following the
column of numbers to sum, use

Dim Addr As String
Dim Rng As Range
Set Rng = ActiveCell.End(xlUp).End(xlUp)
Addr = Rng.Address
ActiveCell.Formula = "=SUM(" & Addr & ":" & ActiveCell(0,
1).Address & ")"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"mkerstei"
wrote in
message
...

I need to write a macro that will sum all of the values above
the
selected cell. Rows above cell are variable, so it has to be
flexible.
Below is my code. I believe the sum formula will be where the
*****
are. Any help would be appreciated. Thanks.

Range("E1").Select
Selection.End(xlDown).Select
ReportLastRow = ActiveCell.Row
ActiveCell.Offset(rowOffset:=1, columnoffset:=0).Activate
ActiveCell.FormulaR1C1 = _
"Total"
ActiveCell.Offset(rowOffset:=0, columnoffset:=1).Activate
ActiveCell.FormulaR1C1 = *****


--
mkerstei
------------------------------------------------------------------------
mkerstei's Profile:
http://www.excelforum.com/member.php...o&userid=25688
View this thread:
http://www.excelforum.com/showthread...hreadid=548761



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Need to Sum all values above

ActiveCell.FormulaR1C1 = "=sum(r1c5:rc[-1])"

===
Or drop the selecting:

Dim myCell As Range
With ActiveSheet
Set myCell = .Range("e1").End(xlDown).Offset(1, 0)
End With
myCell.Value = "Total"
myCell.Offset(0, 1).FormulaR1C1 = "=sum(r1c5:rc[-1])"

mkerstei wrote:

I need to write a macro that will sum all of the values above the
selected cell. Rows above cell are variable, so it has to be flexible.
Below is my code. I believe the sum formula will be where the *****
are. Any help would be appreciated. Thanks.

Range("E1").Select
Selection.End(xlDown).Select
ReportLastRow = ActiveCell.Row
ActiveCell.Offset(rowOffset:=1, columnoffset:=0).Activate
ActiveCell.FormulaR1C1 = _
"Total"
ActiveCell.Offset(rowOffset:=0, columnoffset:=1).Activate
ActiveCell.FormulaR1C1 = *****

--
mkerstei
------------------------------------------------------------------------
mkerstei's Profile: http://www.excelforum.com/member.php...o&userid=25688
View this thread: http://www.excelforum.com/showthread...hreadid=548761


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Need to Sum all values above


Thanks for everyones help!


--
mkerstei
------------------------------------------------------------------------
mkerstei's Profile: http://www.excelforum.com/member.php...o&userid=25688
View this thread: http://www.excelforum.com/showthread...hreadid=548761

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
Excel 2007 doesnt show Y-axis values when the values are small. outback Charts and Charting in Excel 2 October 26th 08 01:37 AM
Exclude #N/A values and Return Numeric values to consecutive cells in Single Row Sam via OfficeKB.com Excel Worksheet Functions 5 February 9th 08 03:07 AM
Search/Filter to find values in another range based on two cell values Andy Excel Programming 2 April 29th 04 04:08 PM
How do I search thr'o column and put unique values in differnt sheet and sum corresponding values in test test Excel Programming 3 September 9th 03 08:53 PM
Predict Y-values on new X-values based on other actual X and Y values? NorTor Excel Programming 2 August 10th 03 03:08 PM


All times are GMT +1. The time now is 04:26 AM.

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"