Find Printed Page Numbers

kajohnson9

New Member
Joined
Jul 29, 2011
Messages
8
I have a workbook with numerous sheets. The first sheet is a Table of Contents sheet. The Table of Contents points to each of the sheets in the workbook, typical Table of Contents function. Is there a way of determining the printed page number without having to include the page number in the sheet name? Some sheets print on multiple pages while other sheets only print on one page.
Thanks,
Keith Johnson
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this:

VBA Code:
Sub findPageNo()
'https://www.mrexcel.com/board/threads/find-printed-page-numbers.1215772/
Dim i As Long
Dim Pgs As Long
Dim Start As Long
Start = 2
'start at the second worksheet through the last worksheet
For i = 2 To ThisWorkbook.Sheets.Count
    'count the page breaks, horizontal and vertical. For every vertical break, you'll have double the pages
    Pgs = Sheets(i).HPageBreaks.Count * (Sheets(i).VPageBreaks.Count + 1)
    'paste the sheet name into a cell on the index page (starting at B6 in this example) and the page range next to it. 
    Sheets(1).Cells(i + 4, 2) = Sheets(i).Name
    Sheets(1).Cells(i + 4, 3) = "'" & Start & " - " & Start + Pgs
    'set up for the next page
    Start = Start + Pgs + 1
Next
End Sub
 
Upvote 0
Try this:

VBA Code:
Sub findPageNo()
'https://www.mrexcel.com/board/threads/find-printed-page-numbers.1215772/
Dim i As Long
Dim Pgs As Long
Dim Start As Long
Start = 2
'start at the second worksheet through the last worksheet
For i = 2 To ThisWorkbook.Sheets.Count
    'count the page breaks, horizontal and vertical. For every vertical break, you'll have double the pages
    Pgs = Sheets(i).HPageBreaks.Count * (Sheets(i).VPageBreaks.Count + 1)
    'paste the sheet name into a cell on the index page (starting at B6 in this example) and the page range next to it.
    Sheets(1).Cells(i + 4, 2) = Sheets(i).Name
    Sheets(1).Cells(i + 4, 3) = "'" & Start & " - " & Start + Pgs
    'set up for the next page
    Start = Start + Pgs + 1
Next
End Sub
 
Upvote 0
I can understand how this works but I get a Subscript Out of Range (Run-time error 9). I'll have to delve into this more.
Thanks for the ideas.
Keith
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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
Back
Top