Jump to content

VBA HELP KAVALI ..


dummyquestion

Recommended Posts

Hi,
I have a workbook with a macro which generates 147+ pages. i would like to have first page, last page and rest of the pages different. my footer should give the count of rows printed till the current page. I am also breaking pages such as each page has 35 rows in it. Below is the code i tried. issue is i am not getting different footer for different page. any other code ayena parle . Thanks in advance.

this is the code..

 

Sheets("Preview").Select
FirstDataRow = 15
RowsPerPage = 35
headrow = FirstDataRow - 1
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
'counting total number of pages 
PageCount = (FinalRow - headrow) / RowsPerPage
PageCount = Application.WorksheetFunction.RoundUp(PageCount, 0)
 
'resetting page breaks like 35 lines per page
Set xWs = Sheets("Preview")
Set findRow = Sheets("Preview").Range("A:A").Find(What:="VIN", LookIn:=xlValues)
findRowNumber = findRow.Row + 2
xRow = 35
xWs.ResetAllPageBreaks
xLastrow = xWs.Range("A" & Rows.Count).End(xlUp).Row
 
For i = xRow + findRowNumber To xLastrow Step xRow
xWs.HPageBreaks.Add Before:=xWs.Cells(i, 1)
 
'different footer value calculation and different footer for each page.
j = j + 1
TotaltillthisPage = 7 * j
 
'different footer value calculation and different footer for last page.
If j = PageCount Then
Totallastpage = (FinalRow - FirstDataRow) / 5
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.CenterFooter = "&""Arial,Bold""&12Total Number of Repairs for Model Year 2017 = " & Format(Totallastpage, "#,##0") & vbNewLine & "Total Number of Repairs to this point= " & Format(TotaltillthisPage, "#,##0") & vbNewLine & " Page: &P of &N"
End With
 
Exit For
 
End If
'different footer value calculation and different footer for each page.
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.CenterFooter = "&""Arial,Bold""&12Total Number of Repairs to this point= " & Format(TotaltillthisPage, "#,##0") & vbNewLine & " Page: &P of &N"
End With
 
Next i
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...