smcallesmesa
asked on
Excel 2013 page subtotals in footer
I have a multi sheet workbook and for one of the worksheets, I want to include subtotals for one column in the footer, I've copied the following code from "Mr Excel" which worked for him but creates a "1004 error" for me:
Sub PrintWithSubTotals()
'info
FirstDataRow = 6
RowsPerPage = 25
ColToTotal = 56
'find how many rows today
HeadRow = FirstRowData - 1
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
PageCount = (FinalRow - HeadRow) / RowsPerPage
PageCount = Application.WorksheetFunct ion.RoundU p(PageCoun t, 0)
For i = 1 To PageCount
ThisPageFirstRow = (i - 1) * RowsPerPage + HeadRow + 1
ThisPageLastRow = ThisPageFirstRow + RowsPerPage - 1
TotalThisPage = Application.WorksheetFunct ion.Sum(Ce lls(ThisPa geFirstRow , ColToTotal).Resize(RowsPer Page, 1))
THIS IS WHERE THE ERROR POPS UP
'change footer for this page
Application.PrintCommunica tion = False
With ActiveSheet.PageSetup
.RightFooter = "20. SubTotal: $" & Format(TotalThisPage, "#,##0.00")
End With
Application.PrintCommunica tion = True
'print this page
ActiveWindow.SelectedSheet s.PrintOut From:=i, To:=i, Copies:=1, Collate:=True, IgnorePrintAreas:=False
Next i
End Sub
Sub PrintWithSubTotals()
'info
FirstDataRow = 6
RowsPerPage = 25
ColToTotal = 56
'find how many rows today
HeadRow = FirstRowData - 1
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
PageCount = (FinalRow - HeadRow) / RowsPerPage
PageCount = Application.WorksheetFunct
For i = 1 To PageCount
ThisPageFirstRow = (i - 1) * RowsPerPage + HeadRow + 1
ThisPageLastRow = ThisPageFirstRow + RowsPerPage - 1
TotalThisPage = Application.WorksheetFunct
THIS IS WHERE THE ERROR POPS UP
'change footer for this page
Application.PrintCommunica
With ActiveSheet.PageSetup
.RightFooter = "20. SubTotal: $" & Format(TotalThisPage, "#,##0.00")
End With
Application.PrintCommunica
'print this page
ActiveWindow.SelectedSheet
Next i
End Sub
Can you upload a sample file representing your sheet?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hey try to help from Microsoft technet forum thread here is the link
https://support.microsoft.com/en-us/kb/273028?wa=wsignin1.0
https://support.microsoft.com/en-us/kb/273028?wa=wsignin1.0
Do you really think anyone will think to look for the SubTotal in the Footer?
ASKER
I feel like a complete idiot, but yes that solved the problem. Many thanks