use this code from tutorial
https://youtu.be/LiuCFr76Dm0
(Sub CustomPrint()
Dim firstDatarow As Integer, rowsPerPage As Integer, colToTotal As Integer, totalCount As Integer, quotaCount As Integer _
, nonquotaCount As Integer, headrow As Integer, finalrow As Integer, pageCount As Integer, i As Integer _
, thisPageFirstRow As Integer, thisPageLastRow As Integer
Dim totalSum As Double, quotaSum As Double, nonqoutaSum As Double
firstDatarow = 9
rowsPerPage = 26
colToTotal = 12
headrow = firstDatarow - 2
finalrow = Cells(Rows.Count, 3).End(xlUp).Row
pageCount = (finalrow - headrow) / rowsPerPage
pageCount = Application.WorksheetFunction.RoundUp(pageCount, 0)
For i = 1 To pageCount
thisPageFirstRow = (i - 1) * rowsPerPage + headrow + 2
thisPageLastRow = thisPageFirstRow + rowsPerPage - 2
totalCount = Application.WorksheetFunction.CountA(Cells(thisPageFirstRow, colToTotal - 5).Resize(rowsPerPage, 1))
quotaCount = Application.WorksheetFunction.CountIfs(Cells(thisPageFirstRow, colToTotal - 3).Resize(rowsPerPage, 1), "South")
nonquotaCount = totalCount - quotaCount
totalSum = Application.WorksheetFunction.Sum(Cells(thisPageFirstRow, colToTotal - 5).Resize(rowsPerPage, 1))
quotaSum = Application.WorksheetFunction.SumIf(Cells(thisPageFirstRow, colToTotal - 3).Resize(rowsPerPage, 1), "South", Cells(thisPageFirstRow, colToTotal - 5).Resize(rowsPerPage, 1))
quotaSum = Format(quotaSum, "0.00")
nonqoutaSum = totalSum - quotaSum
MsgBox quotaCount
MsgBox nonquotaCount
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftFooter = "totalCount : " & Format(totalCount, "#,##0") & Chr(10) & "quotaCount : " & Format(quotaCount, "#,##0") & Chr(10) & "nonquotaCount : " & Format(nonquotaCount, "#,##0") & Chr(10)
End With
With ActiveSheet.PageSetup
.RightFooter = "totalSum : " & Format(totalSum, "#,##0.00") & Chr(10) & "quotaSum : " & Format(quotaSum, "#,##0.00") & Chr(10) & "nonqoutaSum : " & Format(nonqoutaSum, "#,##0.00") & Chr(10)
End With
Application.PrintCommunication = True
' ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut from:=i, To:=i, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False
Next i
End Sub
)
why dont work correctly.but i use both header and footer this code working correctly.