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
smcallesmesaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
Can you upload a sample file representing your sheet?
Rgonzo1971Commented:
Hi,

Maybe replace
    FirstDataRow = 6
    HeadRow = FirstRowData - 1

'with 

    FirstDataRow = 6
    HeadRow = FirstDataRow - 1

Open in new window

Regards

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ankit PareekOnline MarketingCommented:
hey try to help from Microsoft technet forum thread here is the link
https://support.microsoft.com/en-us/kb/273028?wa=wsignin1.0
Roy CoxGroup Finance ManagerCommented:
Do you really think anyone will think to look for the SubTotal in the Footer?
smcallesmesaAuthor Commented:
I feel like a complete idiot, but yes that solved the problem. Many thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.