Grab what the printed page number will be to include in TOC

jdash

New Member
Joined
Mar 14, 2011
Messages
18
Hello,

If I have row references in a worksheet that I want to find out what the printed page number will be, how can I automatically pull the page number that the reference is on to be included in new cell (on the table of contents page)?

Please please anyone!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi

For the # of Pages in the document -

Code:
NoofPgs = ActiveSheet.HPageBreaks.Count + 1

For the row number of the Page Break -
Code:
PgBreakRow =  ActiveSheet.HPageBreaks(PgCt).Location.Row - 1
where PgCt is the Page Number you're looking for and
PgBreakRow is the last row of that Page.

hth
 
Upvote 0
Thanks Mike but I'm sort of still at a loss- is something this what I am supposed to do?

Code:
Sub PgCt()
    PgBreakRow = ActiveSheet.HPageBreaks(PgCt).Location.Row - 1
End Sub

Sub PgBreakRow()
    NoofPgs = ActiveSheet.HPageBreaks.Count + 1
End Sub

I'm really having trouble and have been trying to research a solution for 2 days now..

What seems most silly is that in Page Break preview Excel watermarks the page numbers right there. I'd think that there would be an easy way to just go ahead and insert those page numbers as a value in a cell to say what page data is on. Is the idea that you aren't supposed to print or format a book in Excel? It's crazy that I have to manually enter in each page number to a table of contents.. especially if those page numbers are likely to change.

I would love to see =PageCt($B1) as a formula or UDF...

Can you help me with that?
 
Upvote 0
See http://www.mcgimpsey.com/excel/udfs/pagenumber.html
 
Upvote 0
thanks shg,
i was playing with that already and is very slow. I commented out the Application.volatile line, and still when I go to copy down it hangs way long.. I'm dealing with 13,000+ rows and each row is taking several seconds to compute. It would take an hour each time it needed to recalculate.

There must be a faster way to calculate, no?
 
Upvote 0
Dunno. If you're using Excel 2010, you could try setting application.printcommunication = false, but recognize that the pagination can only come from chatting with the printer driver, and those are slow conversations.

The code could probably be modified to create a collection of the page breaks in a first pass, then compute page numbers for any given cell from those without further discussion with the printer.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

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