Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to count number of pages in worksheet

7,257 views
Skip to first unread message

msnews

unread,
Apr 8, 2008, 2:37:53 AM4/8/08
to
i want to insert the count of total number of pages of a worksheet in a cell
of the same worksheet.
this should be done automatically using worksheet formula or visual basic
code or macro.
please help


NateBuckley

unread,
Apr 8, 2008, 2:53:01 AM4/8/08
to
Hello I hope this helps, go to the code in ThisWorkBook.

You can do this by pushing ALT+F11 then right clicking on "ThisWorkBook" on
the left, and left clicking on view code.

Then paste in the following

Private Sub Workbook_Open()
Sheets("NameOfSheet").Cells(1, 1).Value = Worksheets.Count
End Sub

When the worksheet opens it'll count the number of worksheets and put this
value in a specified cell. So in this case if you had a sheet named
NameOfSheet it would put a number in Row 1, Column A.

Hope this helped.

Rick Rothstein (MVP - VB)

unread,
Apr 8, 2008, 5:01:46 AM4/8/08
to
I am reading your question differently than Nate did... it looks to me like
you want to know how many pages it will take to print out the worksheet
itself (not how many worksheets are in the workbook). If I am right,
copy/paste the following code into the code window for the worksheet you
want this functionality on (right click the worksheet's tab and select View
Code from the popup menu that appears)....

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Whoops
Application.EnableEvents = False
Range("A1").Value = ExecuteExcel4Macro("GET.DOCUMENT(50)")
Whoops:
Application.EnableEvents = True
End Sub

Rick


"NateBuckley" <NateB...@discussions.microsoft.com> wrote in message
news:F0A18399-21EB-4124...@microsoft.com...

S N

unread,
Apr 8, 2008, 5:16:34 AM4/8/08
to
you have guessed it correctly.
i want to know how many pages will print when i give print command on a particular worksheet
 (and not how many worksheets are there in a particular workbook)
 
actually i want to display the following text on a particular column cells
 
page x of y (where x is the particular page on which the cell lies and  y is the total number of pages that would print)
 
please help
 
 
"Rick Rothstein (MVP - VB)" <rick.new...@NO.SPAMverizon.net> wrote in message news:eTm1qcVm...@TK2MSFTNGP05.phx.gbl...

S N

unread,
Apr 8, 2008, 5:21:12 AM4/8/08
to
and i dont want to copy the function or code on all worksheets in my
workbooks. i would like to use something like code in a module file.

i would like to have a general code which i can use in all worksheets of my
workbooks

please help.

"Rick Rothstein (MVP - VB)" <rick.new...@NO.SPAMverizon.net> wrote in
message news:eTm1qcVm...@TK2MSFTNGP05.phx.gbl...

NateBuckley

unread,
Apr 8, 2008, 5:40:17 AM4/8/08
to
My apologies, I misread what you put.

Jean-Yves TFELT

unread,
Apr 8, 2008, 6:36:50 AM4/8/08
to
Hi,


Cant you just use the Header or the Footer section where excel can give you
that automatically ?

Regards
Jean-Yves

"S N" <uand...@yahoo.com> wrote in message
news:OyZ7nnVm...@TK2MSFTNGP05.phx.gbl...

S N

unread,
Apr 11, 2008, 8:03:38 AM4/11/08
to
actually i am using the value in a cell in the table.
hence i cant use header and footer.
i want to have a function for getting the value.
please help.


"Jean-Yves TFELT" <noSpam@I_Hate_Spam> wrote in message
news:12077381...@ecw.eurocontrol.be...

Rick Rothstein (MVP - VB)

unread,
Apr 11, 2008, 9:39:15 AM4/11/08
to
In order for you to be able to put the page number on each page, I guessing
that would mean there are set cells reserved for the page number... what are
those cell addresses?

Rick


"S N" <uand...@yahoo.com> wrote in message

news:ecgyUw8...@TK2MSFTNGP06.phx.gbl...

Sabeel Ather M G

unread,
May 7, 2014, 7:26:13 AM5/7/14
to
@NateBuckley

Your answer is simply smart. Thanks for the techniques.
0 new messages