Problem to use function in header and footer

Status
Not open for further replies.

H7bahar

New Member
Joined
Apr 3, 2018
Messages
4
i use this code from tutorial https://youtu.be/LiuCFr76Dm0
Code:
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.thanks for every thing.
Sample workbook
https://goo.gl/cyKZAw
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Status
Not open for further replies.

Forum statistics

Threads
1,170,953
Messages
5,872,924
Members
432,952
Latest member
Il Prete

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top