Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Sum totals at last row

I am looking to sum several columns (see below) and have the totals listed
on the
last line for each column. I also want to insert the text "TOTAL:" on the
same line in
column A. Following is where I am but I am stuck. Any help would be
appreciated.

Thanks,

Met



CODE, So far:

Application.sum (Range("D2:D"))
Application.sum (Range("E2:E"))
Application.sum (Range("F2:F"))
Application.sum (Range("G2:G"))
Application.sum (Range("H2:H"))
Application.sum (Range("I2:I"))
Application.sum (Range("J2:J"))
Application.sum (Range("K2:K"))
Application.sum (Range("L2:L"))
Application.sum (Range("M2:M"))
Application.sum (Range("N2:N"))
Application.sum (Range("O2:O"))
Application.sum (Range("P2:P"))
Application.sum (Range("Q2:Q"))
Application.sum (Range("R2:R"))
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sum totals at last row

Sub AddSums()
Dim lastrow as long, cell as Range
lastrow = cells(rows.count,"D").End(xlup)(2).row
for each cell in Range("D2:R2")
cells(lastrow,cell.column).Value =
application.Sum(cell.Resize(lastrow-2,1))
Next
cells(lastrow,"A").Value = "TOTAL:"
End Sub

--
Regards,
Tom Ogilvy



"Metrazal" <u19384@uwe wrote in message news:5cddf81ae168b@uwe...
I am looking to sum several columns (see below) and have the totals

listed
on the
last line for each column. I also want to insert the text "TOTAL:" on

the
same line in
column A. Following is where I am but I am stuck. Any help would be
appreciated.

Thanks,

Met



CODE, So far:

Application.sum (Range("D2:D"))
Application.sum (Range("E2:E"))
Application.sum (Range("F2:F"))
Application.sum (Range("G2:G"))
Application.sum (Range("H2:H"))
Application.sum (Range("I2:I"))
Application.sum (Range("J2:J"))
Application.sum (Range("K2:K"))
Application.sum (Range("L2:L"))
Application.sum (Range("M2:M"))
Application.sum (Range("N2:N"))
Application.sum (Range("O2:O"))
Application.sum (Range("P2:P"))
Application.sum (Range("Q2:Q"))
Application.sum (Range("R2:R"))



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Sum totals at last row

Met
This macro should do what you want. HTH Otto
Sub SumColumns()
Dim c As Long
Dim LastRow As Long
LastRow = Range("D" & Rows.Count).End(xlUp).Row
Cells(LastRow + 1, 1).Value = "TOTAL"
For c = 4 To 18
Cells(LastRow + 1, c).Value = Application.Sum(Range(Cells(2, c),
Cells(LastRow, c)))
Next c
End Sub
"Metrazal" <u19384@uwe wrote in message news:5cddf81ae168b@uwe...
I am looking to sum several columns (see below) and have the totals
listed
on the
last line for each column. I also want to insert the text "TOTAL:" on
the
same line in
column A. Following is where I am but I am stuck. Any help would be
appreciated.

Thanks,

Met



CODE, So far:

Application.sum (Range("D2:D"))
Application.sum (Range("E2:E"))
Application.sum (Range("F2:F"))
Application.sum (Range("G2:G"))
Application.sum (Range("H2:H"))
Application.sum (Range("I2:I"))
Application.sum (Range("J2:J"))
Application.sum (Range("K2:K"))
Application.sum (Range("L2:L"))
Application.sum (Range("M2:M"))
Application.sum (Range("N2:N"))
Application.sum (Range("O2:O"))
Application.sum (Range("P2:P"))
Application.sum (Range("Q2:Q"))
Application.sum (Range("R2:R"))



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Sum totals at last row

Almost... It totals but for some reason it misses the lastrow. It puts the
data on
row 109 instead of row 112, of course the rows will vary depending on when I
run the code. But its almost there. What am I missing?

Thanks,

Met

Tom Ogilvy wrote:
Sub AddSums()
Dim lastrow as long, cell as Range
lastrow = cells(rows.count,"D").End(xlup)(2).row
for each cell in Range("D2:R2")
cells(lastrow,cell.column).Value =
application.Sum(cell.Resize(lastrow-2,1))
Next
cells(lastrow,"A").Value = "TOTAL:"
End Sub

I am looking to sum several columns (see below) and have the totals listed
on the

[quoted text clipped - 24 lines]
Application.sum (Range("Q2:Q"))
Application.sum (Range("R2:R"))

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sum totals at last row

Sub AddSums()
Dim lastrow As Long, cell As Range
With ActiveSheet
.UsedRange
lastrow = .UsedRange.Item(.UsedRange.Count).Row + 1
End With
For Each cell In Range("D2:R2")
Cells(lastrow, cell.Column).Value = _
Application.Sum(cell.Resize(lastrow - 2, 1))
Next
Cells(lastrow, "A").Value = "TOTAL:"
End Sub



--
Regards,
Tom Ogilvy



"Metrazal" <u19384@uwe wrote in message news:5cded84df87ef@uwe...
Almost... It totals but for some reason it misses the lastrow. It puts

the
data on
row 109 instead of row 112, of course the rows will vary depending on when

I
run the code. But its almost there. What am I missing?

Thanks,

Met

Tom Ogilvy wrote:
Sub AddSums()
Dim lastrow as long, cell as Range
lastrow = cells(rows.count,"D").End(xlup)(2).row
for each cell in Range("D2:R2")
cells(lastrow,cell.column).Value =
application.Sum(cell.Resize(lastrow-2,1))
Next
cells(lastrow,"A").Value = "TOTAL:"
End Sub

I am looking to sum several columns (see below) and have the totals

listed
on the

[quoted text clipped - 24 lines]
Application.sum (Range("Q2:Q"))
Application.sum (Range("R2:R"))



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
Pivot Totals: Group totals different from Grand totals PsyberFox Excel Discussion (Misc queries) 1 February 13th 08 06:16 PM
how to enter totals and sub totals from receipts into excel. mjd23 New Users to Excel 2 January 11th 08 01:54 AM
Summing Weekly Totals into Monthly Totals steph44haf Excel Worksheet Functions 3 July 5th 06 04:51 PM
How do I sum YTD totals based on monthly totals Bsgrad02 Excel Discussion (Misc queries) 3 July 12th 05 04:59 PM
Comparing/matching totals in a column to totals in a row Nicole L. Excel Worksheet Functions 3 January 27th 05 10:42 PM


All times are GMT +1. The time now is 11:18 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"