I re-read you instruction and I think I got it right this time. I used a sum
formula to sum all the sheets for each of the cells in the area B6:S61 like
this
=Sum(Sheet1:Rheet31!R6C2)
I'm using R1C1 addressing, but it gets translated to be A1 addressing. If
the sheet name are not 1 and 31 then change the instruction like this
=Sum(alpha:zeta!R6C2)
if there are spaces then we need to add single quotes
=Sum('alpha 1:zeta 4'!R6C2)
Sub totalbooks()
Folder = "C:\Report"
AllFileName = "Alltotals"
LenAll = Len(AllFileName)
'Open All total book
Set Allbk = Workbooks.Open(Filename:=Folder & "\" _
& AllFileName & ".xls")
Set AllSht = Allbk.Sheets(2)
'find last row of in column A
LastRow = AllSht.Range("A" & Rows.Count).End(xlUp).Row
'Newrow is row where report total is put
NewRow = LastRow
FName = Dir(Folder & "\*.xls")
Do While FName <> ""
'Don't open allmonth files
If Left(UCase(FName), LenAll) <> UCase(AllFileName) Then
Set Reportbk = Workbooks.Open(Filename:=Folder & "\" & FName)
Set Report_T_Sht = Reportbk.Sheets("Total")
For RowCount = 6 To 60
For ColCount = sht.Range("B6").Column To sht.Range("S6").Column
Report_T_Sht.Cells(RowCount, ColCount).FormulaR1C1= _
"=Sheet1:Sheet31!R" & RowCount & "C" & ColCount
Next ColCount
Next RowCount
Set TotalRange = Report_T_Sht.Range("B6:S60")
Total = WorksheetFunction.Sum(TotalRange)
NewRow = NewRow + 1
AllSht.Range("A" & NewRow) = FName
AllSht.Range("B" & NewRow) = Total
Reportbk.Close
End If
FName = Dir()
Loop
'add total to All total book as a formula
AllSht.Range("A" & (NewRow + 2)) = "GRAND TOTL"
AllSht.Range("B" & (NewRow + 2)).Formula = _
"=SUM(B" & (LastRow + 1) & ":B" & NewRow & ")"
bkMonth = AllSht.Range("R1")
bkYear = AllSht.Range("S1")
Allbk.SaveAs Filename:=Folder & "\" & AllFileName & bkMonth & bkYear
Allbk.Close SaveAs:=False
End Sub
- Show quoted text -
Thanks Joel,
Re: why is the sum range 54 rows (Row 6 to 61) when you have only 31
sheets? I will try to explain clearer. I appreciate your effort.
I am trying to understand the code. It is summing all sheets 1 to
31. I don't need this because all the totals of sheets 1 to 31 in
each workbook are in the 32nd sheet called 'total'. Sorry, I should
have been clearer. It is only these 'total' sheets that I am trying
to sum into the corresponding cells in the allworkbooks file.
Eg, file1 'total" b6 + file 2 'total" b6 + file 3 'total b6
+ ....file 50 'total' b6 to give a total in allworkbooks sheet 2 b6
file1 'total" c6 + file 2 'total" c6 + file 3 'total c6
+ ....file 50 'total' c6 to give a total in allworkbooks sheet 2
c6....
file1 'total" s6 + file 2 'total" s6 + file 3 'total s6
+ ....file 50 'total' s6 to give a total in allworkbooks sheet 2
s6....
file1 'total" b61 + file 2 'total" b61 + file 3 'total
cb61+ ....file 50 'total' b61 to give a total in allworkbooks sheet
2 C61
file1 'total" s61 + file 2 'total" s61 + file 3 'total
sb61+ ....file 50 'total' s61 to give a total in allworkbooks sheet
2 s61....
for all individual cells in that range.
I should mention (it may be relvant) that the totals sheets are
protected sheet (the password is t)
I hope this makes things clearer.
Regards
Bob
I also got On the line, For ColCount = sht.Range("B6").Column To
sht.Range("S6").Column, I get 'Run time Error 424, object required"