I am trying to enter a pagination function that will return “Page X Of Y” in a cell on several worksheets, where X is the current page number and Y is the total number of worksheets. Any ideas?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
“Page x of y” in cell
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » “Page x of y” in cell
- This topic has 29 replies, 6 voices, and was last updated 24 years ago.
Viewing 0 reply threadsAuthorReplies-
WSrory
AskWoody LoungerFebruary 27, 2001 at 1:02 pm #516478Hi,
I don’t know of any built in way of doing it but you could use a user-defined function like this:
Function PageNum() As String
Application.Volatile
PageNum = “Page ” & Application.Caller.Parent.Index & ” of ” & Sheets.Count
End Function
to do it (assuming that by page number you mean sheet number rather than a reference to the number in the printing order)
Hope that helps. -
WSColinBurrows
AskWoody LoungerFebruary 27, 2001 at 2:01 pm #516488Rory,
That’s neat – I’d not seen Application.Caller before. It reminded me of a question, though. If I put that function in my Personal.xls to use in any workbook, I’d have to enter
“=Personal.xls!PageNum()” rather than just “=PageNum()”.
In order for the latter to work, would I need to use an add-in? -
WSrory
AskWoody LoungerFebruary 27, 2001 at 4:46 pm #516515 -
WSAndrew Cronnolly
AskWoody LoungerFebruary 27, 2001 at 8:00 pm #516547If you have two workbooks, the value returned by that function gives the total number of pages of the active book, regardless of the sheet the function is actually in.
If Workbook A has 3 sheets and sheet 1 contains that formula, but Workbook B, with 10 sheets, is active the formula in Book A returns Page 1 of 10.
Just something I noticed as it may have significance in certain circumstances.
Regards,
Andrew C
-
WSrory
AskWoody Lounger -
WSTomG
AskWoody LoungerFebruary 28, 2001 at 12:09 am #516591Do you and jlkirk mean sheet X of Y instead of Page?
When using the code, if you use the function in cell A1 on sheet2, you get 2 of X, the 2= sheet 2, not the first page that would be printed on sheet 2. Or am I just confused by what is meant by “where X is the current page”
Also, Sheets.count is going to return the total number of sheets including chart sheets. Worksheets.count will return the number of worksheets not including any chart sheets. (Didn’t know if that’s a consideration)
j/w
-
WSrory
AskWoody Lounger
-
-
-
-
WSjlkirk
AskWoody LoungerFebruary 28, 2001 at 6:59 am #516634Rory,
Thanks for your response. I should have been clearer-the term “Page” actually refers to worksheets in the workbook. For example, “Page 2 of 10” would appear on the 2nd worksheet in a workbook containing 10 worksheets.
In addition, I am very unfamiliar with working with user-defined functions. How and where do I insert it in the subject workbook-which worksheet, what do I type, etc.?
Thanks,
Jeff
-
WSAndrew Cronnolly
AskWoody LoungerFebruary 28, 2001 at 9:49 am #516650Hi Jeff,
To include Rory’s function you need to launch the VB Editor by pressing Alt-F11 whilst Excel is running. On the left window you should see a list of “Projects”. If you would like the function to be available to all your workbooks you should select VBAProject(Personal.xls), Click on Insert|Module. You can then copy the text of Rory’s function from the above and paste it into the large window of the VB editor.
The function should then be available and can be accessed through the paste function button (fx), where it will be shown as Personal.xls!PageNum. (If you want to enter it manually just type Personal.xls!PageNum().)
To retain the function don’t forget to save changes to Personal.xls before closing Excel.
Strictly speaking the function returns the Tab order of the sheet rather than the order in which the sheet was inserted. You could have Sheet1 with the above function returning Page 1 of 1 but if you insert a sheet before sheet1, it will return Page 2 of 1, even though the sheet name is still Sheet1. This is probably a good thing, but something that you might like to be aware of.
Hope I did not confuse you,
Andrew C
-
WSjlkirk
AskWoody LoungerFebruary 28, 2001 at 10:32 am #516659 -
WSAndrew Cronnolly
AskWoody LoungerFebruary 28, 2001 at 11:21 am #516665Jeff,
You are not dumb, I am. I should not have assumed that you had a personal.xls.
Just to get the thing working and to avoid further confusion, select whatever workbook you have open, a good one being the one you want to have the function operational in. So instead of VBAProject(Personal.xls) you could find VBAProject(OpenBook.xls) wher OpenBook is the name of the book you have open.
Then copy the following green text ( I hope Rory does not mind) :
Function PageNum() As String
With Application
.Volatile
With .Caller.Parent
PageNum = “Page ” & .Index & ” of ” & .Parent.Sheets.Count
End With
End With
End Functionand paste as described before. If that does not work let me know.
The 3rd paragraph of last reply merely says that if you change the tab order of the sheet the “page” number changes accordingly. (the sheet tab is that little appendage at the bottom that shows the sheets name)
Hope I have not confused you even more.
-
WSjlkirk
AskWoody LoungerFebruary 28, 2001 at 11:44 am #516668Andrew,
I tried it (at least I think I did) but it returned that it function had no arguments, or something like that.
If I could, would you mind setting this thing up in the attached workbook to number the 6 Sample worksheets? If possible, design it so the “Page X of Y” appears in A1 of each worksheet. Also, once I have it on this on, how can I make it available for all of my excel workbooks?
Whew! I never thought such a simple task could be so involved!
Thanks,
Jeff -
WSrory
AskWoody LoungerFebruary 28, 2001 at 12:09 pm #516669Hi Jeff,
Attached is your sample workbook with the function in it. To make it available to all workbooks you’ll either have to paste the code into each one or paste it into Personal.xls and call it from there (if you do that you’ll need to use =Personal.xls!PageNum() as your formula)
Just to satisfy my curiosity, why do you want to do this? I can understand it on a printout but have never seen it used for on-screen documents. -
WSjlkirk
AskWoody Lounger -
WSBrooke
AskWoody LoungerFebruary 28, 2001 at 12:32 pm #516674Hiya,
for the non-vba minded, here’s the best I can come up with. Cedit where due to David Hager.
(eee03 for those who are interested. Anybody know what happened to those, by the way?)a) define the name shtPOS as =GET.DOCUMENT(87)
enter the following formula in all sheets in A2
=”Sheet ” & shtPOS & ” of ” & COUNTA(Sheet1:Sheet3!A1)
c) put a title in all sheets in A1
i) I can’t think of a way to do it without names.
ii) It would be a lot neater if anyone knew how to return the total sheet through GET.DOCUMENT() I couldn’t locate this in any of the eee’s i’ve got(1 thru 19).HTH
Brooke
-
WSrory
AskWoody LoungerFebruary 28, 2001 at 12:40 pm #516676Hi Jeff,
What do you mean by ‘activate’ it? The result should be appearing in cell A1 of each sheet unless you have macros disabled.
However, if you only need this for printing you can insert page numbers into a footer by choosing File-Page Setup, select the Header/Footer tab and in the footer (or header) dropdown box about the second item should be ‘Page 1 of ?’.
This will return the number of printed pages (i.e. each worksheet could be more than one printed page) rather than the number of sheets. Is that what you wanted? (if so, that will teach me to ask more questions before launching into code writing!!)
-
WSjlkirk
AskWoody Lounger -
WSrory
AskWoody Lounger -
WSjlkirk
AskWoody Lounger -
WSrory
AskWoody LoungerMarch 2, 2001 at 8:31 am #517055Jeff,
If you already have a personal macro workbook you can copy the code into a module in there and then change your formula to =Personal.xls!pagenum()
If you don’t already have a personal macro workbook, select Tools-Macro-Record New Macro, choose to store it in Personal Macro Workbook, select OK, then press Stop on the macro toolbar. This will create a workbook called Personal.xls in your XLSTART directory which will open (hidden) every time you start Excel. You can then copy the code into this workbook.
Hope that helps. -
WSjlkirk
AskWoody Lounger -
WSrory
AskWoody Lounger -
WSjlkirk
AskWoody LoungerMarch 18, 2001 at 12:46 pm #519314Rory,
Me again-any way to add this as an “add-in” so that it will automatically “attach” to a new file?
If not, please explain in detail (and in very simple terms for me) how I can add this feature to each Excel file I already have created or will create in the future.
Thanks in advance.
Jeff -
WSrory
AskWoody LoungerMarch 21, 2001 at 9:57 am #519691Hi Jeff,
Sorry for the delay – I’ve been swamped recently. I see Andrew has kindly shown you how to add it to your personal macro workbook so this is more for information than anything:
1. You could make this available to future workbooks by adding the code to a new blank workbook and then saving that workbook as book.xlt in your xlstart directory.
2. You could make it available to all your workbooks by adding the code to a new blank workbook, saving the workbook as PageNum.xla in your add-ins directory and then go to Tools-Add-Ins and check PageNum. You can then simply type =PageNum() in whichever cell you want. It’s probably a bit over the top to create an add-in for just one function though! -
WSjlkirk
AskWoody Lounger -
WSAndrew Cronnolly
AskWoody Lounger -
WSjlkirk
AskWoody Lounger -
WSAndrew Cronnolly
AskWoody LoungerMarch 19, 2001 at 10:15 am #519379Jeff no problem.
First check to see if you a personal.xls by pressing Alt-F11. The VBA editor should open. in the left pane you see a list with titles like VBAProject(Bookname) , where bookname represents the names of your open workbooks. If you can see VBAProject(PERSONAL.XLS) then there is not need to create a new one. If you do not see that project listed, then open a new blank workbook. Save it as Personal.xls in your XLStart directory. The path to XLStart depends on your installation of Office. Try searching for it with Windows Explorer.
You then need to copy the Function to personal.xls. To do this you might need to highlight VBAProject(Persoan.xls) and go to Insert Module. Then just enter the text of the function. When that is done go back to excel and select personal.xls., goto Window, Hide.
Close all other books and exit Excel. When asked to keep changes to personal.xls select yes. Exit Excel and restart. The function you created should now be available to all your workbooks. There is a snag in that =PERSONAL.XLS! needs to be inserted before the function name. However that can be easy by using Insert Function, and selecting User Defined.
Hope you can make sense of that.
Andrew
-
WSrory
AskWoody Lounger
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Office apps read-only for family members
by
b
8 minutes ago -
Defunct domain for Microsoft account
by
CWBillow
5 hours, 30 minutes ago -
24H2??
by
CWBillow
2 hours, 4 minutes ago -
W11 23H2 April Updates threw ‘class not registered’
by
WindowsPersister
2 hours, 48 minutes ago -
Master patch listing for April 8th, 2025
by
Susan Bradley
9 hours, 3 minutes ago -
TotalAV safety warning popup
by
Theodore Nicholson
2 hours, 29 minutes ago -
two pages side by side land scape
by
marc
1 day, 15 hours ago -
Deleting obsolete OneNote notebooks
by
afillat
1 day, 17 hours ago -
Word/Outlook 2024 vs Dragon Professional 16
by
Kathy Stevens
20 hours, 49 minutes ago -
Security Essentials or Defender?
by
MalcolmP
23 hours, 34 minutes ago -
April 2025 updates out
by
Susan Bradley
6 hours, 8 minutes ago -
Framework to stop selling some PCs in the US due to new tariffs
by
Alex5723
16 hours, 55 minutes ago -
WARNING about Nvidia driver version 572.83 and 4000/5000 series cards
by
Bob99
7 hours ago -
Creating an Index in Word 365
by
CWBillow
1 day, 9 hours ago -
Coming at Word 365 and Table of Contents
by
CWBillow
1 day, 1 hour ago -
Windows 11 Insider Preview Build 22635.5170 (23H2) released to BETA
by
joep517
2 days, 12 hours ago -
Has the Microsoft Account Sharing Problem Been Fixed?
by
jknauth
2 days, 16 hours ago -
W11 24H2 – Susan Bradley
by
G Pickerell
2 days, 18 hours ago -
7 tips to get the most out of Windows 11
by
Alex5723
2 days, 16 hours ago -
Using Office apps with non-Microsoft cloud services
by
Peter Deegan
2 days, 9 hours ago -
I installed Windows 11 24H2
by
Will Fastie
15 hours, 52 minutes ago -
NotifyIcons — Put that System tray to work!
by
Deanna McElveen
2 days, 21 hours ago -
Decisions to be made before moving to Windows 11
by
Susan Bradley
3 hours, 2 minutes ago -
Port of Seattle says ransomware breach impacts 90,000 people
by
Nibbled To Death By Ducks
3 days, 5 hours ago -
Looking for personal finance software with budgeting capabilities
by
cellsee6
2 days, 14 hours ago -
ATT/Yahoo Secure Mail Key
by
Lil88reb
2 days, 14 hours ago -
Devices with apps using sprotect.sys driver might stop responding
by
Alex5723
3 days, 23 hours ago -
Neowin – 20 times computers embarrassed themselves with public BSODs and goofups
by
EP
4 days, 7 hours ago -
Slow Down in Windows 10 performance after March 2025 updates ??
by
arbrich
7 hours ago -
Mail from certain domains not delivered to my outlook.com address
by
pumphouse
3 days, 15 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.