View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Jodie Jodie is offline
external usenet poster
 
Posts: 72
Default Macro to sum columns in all sheets in a workbook

Thank you Joel. I will give it a try and let you know how it goes.
--
Thank you, Jodie


"joel" wrote:


Something like this. You have to skip the original shet that you split
and I included row 1 which you also may want to change to row 2. I'm
using column A to determine the last row and putting the total and the
next row after the last row.

Sub test()

firstCol = ActiveSheet.Columns("G").Column
LastCol = ActiveSheet.Columns("O").Column


For Each Sht In Sheets
With Sht
'find last row using column A
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
SumRow = LastRow + 1
'Add formula to worksheet to add first column
Set SumRange = .Range(.Cells(1, firstCol), .Cells(LastRow,
firstCol))
.Cells(SumRow, firstCol).Formula = _
"=Sum(" & SumRange.Address(ColumnAbsolute:=False) & ")"

'copy the formula across all the columns
.Cells(SumRow, firstCol).Copy _
Destination:=.Range(.Cells(SumRow, firstCol), .Cells(SumRow,
LastCol))
'Put Total in column a
.Range("A" & SumRow) = "Total"
End With
Next Sht

End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=148941

.