Jimmypop
Well-known Member
- Joined
- Sep 12, 2013
- Messages
- 753
- Office Version
- 365
- Platform
- Windows
Good day all
Some assistance required...
I need the number of pages for workbook (2 sheets)... hereafter is some info regarding the sheet/s
1. Sheet2 will always be 1 page (the last page)
2. Sheet1 starts of on 1 page and goes to a maximum of 8 pages.
3. Sheet1 in cell K2 should display the following Page 1 of 2 or Page 1 of 5 etc. depending on the number of pages on Sheet1 plus 1 page from Sheet2. (Number of pages on Sheet1 is determined by hiding and unhiding rows).
4. Sheet1 is in page break view.
So in short... after report is finished, K2 on Sheet1 should show the total number of pages of the workbook depending on the amount on Sheet1, e.g. Sheet1 has 4 pages so K2 should show Page 1 of 5 (4 pages from Sheet1 and 1 page from Sheet2) OR Sheet1 has 8 pages so K2 should show Page 1 of 9 (8 pages from Sheet1 and 1 page from Sheet2)...
Found this code below but it only shows the total of Sheet1 including hidden rows (Shows Page 1 of 8 all the time)
Some assistance required...
I need the number of pages for workbook (2 sheets)... hereafter is some info regarding the sheet/s
1. Sheet2 will always be 1 page (the last page)
2. Sheet1 starts of on 1 page and goes to a maximum of 8 pages.
3. Sheet1 in cell K2 should display the following Page 1 of 2 or Page 1 of 5 etc. depending on the number of pages on Sheet1 plus 1 page from Sheet2. (Number of pages on Sheet1 is determined by hiding and unhiding rows).
4. Sheet1 is in page break view.
So in short... after report is finished, K2 on Sheet1 should show the total number of pages of the workbook depending on the amount on Sheet1, e.g. Sheet1 has 4 pages so K2 should show Page 1 of 5 (4 pages from Sheet1 and 1 page from Sheet2) OR Sheet1 has 8 pages so K2 should show Page 1 of 9 (8 pages from Sheet1 and 1 page from Sheet2)...
Found this code below but it only shows the total of Sheet1 including hidden rows (Shows Page 1 of 8 all the time)
VBA Code:
Sub pagenumber()
'updateby Extendoffice 20160506
Dim xVPC As Integer
Dim xHPC As Integer
Dim xVPB As VPageBreak
Dim xHPB As HPageBreak
Dim xNumPage As Integer
xHPC = 1
xVPC = 1
If ActiveSheet.PageSetup.Order = xlDownThenOver Then
xHPC = ActiveSheet.HPageBreaks.Count + 1
Else
xVPC = ActiveSheet.VPageBreaks.Count + 1
End If
xNumPage = 1
For Each xVPB In ActiveSheet.VPageBreaks
If xVPB.Location.Column > ActiveCell.Column Then Exit For
xNumPage = xNumPage + xHPC
Next
For Each xHPB In ActiveSheet.HPageBreaks
If xHPB.Location.Row > ActiveCell.Row Then Exit For
xNumPage = xNumPage + xVPC
Next
ActiveCell = "Page " & xNumPage & " of " & Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
End Sub