Link to home
Start Free TrialLog in
Avatar of smcallesmesa
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.WorksheetFunction.RoundUp(PageCount, 0)
   
    For i = 1 To PageCount
        ThisPageFirstRow = (i - 1) * RowsPerPage + HeadRow + 1
        ThisPageLastRow = ThisPageFirstRow + RowsPerPage - 1
        TotalThisPage = Application.WorksheetFunction.Sum(Cells(ThisPageFirstRow, ColToTotal).Resize(RowsPerPage, 1))
   
THIS IS WHERE THE ERROR POPS UP
   
        'change footer for this page
       Application.PrintCommunication = False
             
        With ActiveSheet.PageSetup
            .RightFooter = "20. SubTotal: $" & Format(TotalThisPage, "#,##0.00")
        End With
        Application.PrintCommunication = True
       
        'print this page
        ActiveWindow.SelectedSheets.PrintOut From:=i, To:=i, Copies:=1, Collate:=True, IgnorePrintAreas:=False
       
    Next i
       
       End Sub
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Can you upload a sample file representing your sheet?
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hey try to help from Microsoft technet forum thread here is the link
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?
Avatar of smcallesmesa
smcallesmesa

ASKER

I feel like a complete idiot, but yes that solved the problem. Many thanks