Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macro to sum an unknown range

I have a worksheet that I import data into weekly. I have a macro that
formats all the data on separate sheets, etc. I'm trying to add a
macro that will sum the totals with a beginning range that is always
the same but the bottom of the range is always different. I use a
relative macro that takes me to the last cell with data to actually put
the total in. Now, how do i get it to total from that cell always up
to row 2?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default macro to sum an unknown range

To do with a macro, use this. This is for col D. Change to suit

Sub sumem()
x = Cells(65536, "d").End(xlUp).Row
MsgBox Application.Sum(Range(Cells(2, 4), Cells(x, 4)))
End Sub

"susiel" wrote in message
...
I have a worksheet that I import data into weekly. I have a macro that
formats all the data on separate sheets, etc. I'm trying to add a
macro that will sum the totals with a beginning range that is always
the same but the bottom of the range is always different. I use a
relative macro that takes me to the last cell with data to actually put
the total in. Now, how do i get it to total from that cell always up
to row 2?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default macro to sum an unknown range

To put at the bottom of the column
Sub sumem()
x = Cells(65536, "d").End(xlUp).Row
cells(x+1,"d") = Application.Sum(Range(Cells(2, 4), Cells(x, 4)))
End Sub



"Don Guillett" wrote in message
...
To do with a macro, use this. This is for col D. Change to suit

Sub sumem()
x = Cells(65536, "d").End(xlUp).Row
MsgBox Application.Sum(Range(Cells(2, 4), Cells(x, 4)))
End Sub

"susiel" wrote in message
...
I have a worksheet that I import data into weekly. I have a macro that
formats all the data on separate sheets, etc. I'm trying to add a
macro that will sum the totals with a beginning range that is always
the same but the bottom of the range is always different. I use a
relative macro that takes me to the last cell with data to actually put
the total in. Now, how do i get it to total from that cell always up
to row 2?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default macro to sum an unknown range

Susie,

To add the SUM formula, use a macro like that below.

HTH,
Bernie

Sub SumAtBottomOfCurrentColumn()
Dim myCell As Range
Set myCell = Cells(65536, ActiveCell.Column).End(xlUp)(2)
With myCell
.Formula = "=SUM(" & _
Range(.Offset(-1, 0), _
Cells(2, .Column)).Address(False, False) & ")"
End With
End Sub


"susiel" wrote in message
...
I have a worksheet that I import data into weekly. I have a macro

that
formats all the data on separate sheets, etc. I'm trying to add a
macro that will sum the totals with a beginning range that is always
the same but the bottom of the range is always different. I use a
relative macro that takes me to the last cell with data to actually

put
the total in. Now, how do i get it to total from that cell always

up
to row 2?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default macro to sum an unknown range

Sub Tester1()
Dim rng As Range
Set rng = Cells(Rows.Count, ActiveCell.Column).End(xlUp)(2)
rng.FormulaR1C1 = "=Sum(R2C:R[-1]C)"
End Sub

Regards,
Tom Ogilvy


"susiel" wrote in message
...
I have a worksheet that I import data into weekly. I have a macro that
formats all the data on separate sheets, etc. I'm trying to add a
macro that will sum the totals with a beginning range that is always
the same but the bottom of the range is always different. I use a
relative macro that takes me to the last cell with data to actually put
the total in. Now, how do i get it to total from that cell always up
to row 2?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



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
Unknown Range in Macro scone57 Excel Discussion (Misc queries) 7 February 5th 09 03:33 PM
Counting an Unknown Range atryon Excel Discussion (Misc queries) 1 May 5th 08 08:44 PM
sorting unknown range peyman Excel Discussion (Misc queries) 10 October 20th 07 08:34 PM
HELP! Unknown range Excel_Oz Excel Worksheet Functions 3 March 16th 07 01:35 AM
Average of Unknown Range Mike Excel Discussion (Misc queries) 9 March 24th 06 03:37 PM


All times are GMT +1. The time now is 11:30 AM.

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

About Us

"It's about Microsoft Excel"