Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Dynamically sum rows

I have a function that exports rows of data to an Excel spreadsheet template.
Is there a way to dynamically show the sum of each column after the last row
of data since my function may not always export the same amount of rows. I
always want to show the sum to the rows after the last row of data. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default Dynamically sum rows

Does your sum cell have to be below the last row of data or can you create a
sum area just above the header row? Then you can use (i.e.) =SUM(b5:b65536)
and all your data will be captured whether you add/remove rows, etc.

"Akilah" wrote:

I have a function that exports rows of data to an Excel spreadsheet template.
Is there a way to dynamically show the sum of each column after the last row
of data since my function may not always export the same amount of rows. I
always want to show the sum to the rows after the last row of data. Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Dynamically sum rows

You will have to use a macro to do this. Try the below which will put the
autosum for all the columns..If you are new to macros set the Security level
to low/medium in (Tools|Macro|Security). From workbook launch VBE using
short-key Alt+F11. From menu 'Insert' a module and paste the below code.
Save. Get back to Workbook. Run macro from Tools|Macro|Run <selected macro()


Sub Macro1()
Dim lngCol As Long
Dim lngLastRow As Long
Dim lngLastCol As Long
'Find last Row in ColumnA
lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
'Find last Col in the last Row
lngLastCol = ActiveSheet.Cells(lngLastRow, _
Columns.Count).End(xlToLeft).Column
'Loop until last Column
For lngCol = 1 To lngLastCol
'Fill the cells with formula
Cells(lngLastRow + 1, lngCol).FormulaR1C1 = "=SUM(R[-" & lngLastRow &
"]C:R[-1]C)"
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Akilah" wrote:

I have a function that exports rows of data to an Excel spreadsheet template.
Is there a way to dynamically show the sum of each column after the last row
of data since my function may not always export the same amount of rows. I
always want to show the sum to the rows after the last row of data. Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,346
Default Dynamically sum rows

Hi,

Since we don't know how your data is laid out we can't propose the actual
code but here is an example in which you select the top row of the cells you
want to sum:

Sub AddFormula()
Dim Bot As String
Dim Top As String
Dim cell As Range
For Each cell In Selection
Bot = cell.End(xlDown).Address
Top = cell.Address
Range(Bot).Offset(1, 0) = "=SUM(" & Top & ":" & Bot & ")"
Next cell
End Sub

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Akilah" wrote:

I have a function that exports rows of data to an Excel spreadsheet template.
Is there a way to dynamically show the sum of each column after the last row
of data since my function may not always export the same amount of rows. I
always want to show the sum to the rows after the last row of data. Thanks.

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
Dynamically create range of rows Avi Dubnikov Excel Discussion (Misc queries) 2 August 25th 07 02:00 AM
Dynamically display in Active Cell value from 2 rows above it Jocko_MacDuff116 Excel Discussion (Misc queries) 4 May 12th 07 04:08 AM
Insert a specified number of rows dynamically ttbbgg Excel Worksheet Functions 2 March 20th 06 08:27 PM
Dynamically OCntrolling Rows jliz2803 Excel Worksheet Functions 0 February 13th 06 03:43 PM
formula to use when number of rows changes dynamically confused Excel Worksheet Functions 3 August 17th 05 03:55 PM


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

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"