excel page numbers into
Microsoft Office TrainingThe UK's Number 1 for Microsoft Office Training Sitemap add this page to your favourites/bookmarksBookmark page
 
view a printable version of this pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel page numbers into variables

Excel page numbers into variables

resolvedResolved · Medium Priority · Version 2003

replyReplyWed 3 Sep 2008, 18:31Delegate Roy said...

Excel page numbers into variables

I want to get the page number that a given cell in the current print selection will appear on into a variable or a cell outside the print area - how can this be done?

For upcoming training course dates see: Pricing & availability

replyReplyWed 17 Sep 2008, 13:13Trainer Laura said...

RE: Excel page numbers into variables

Hi Roy

Thanks for the question, its a tricky one.

There is no easy property or method of a cell to tell you which page it is on. There are ways of calculating it but they are complex.

To find out if a cell is in the print area you can use

not intersect(range("d1"),Range("print_area")) is nothing

which will return True if D1 is inside the print area. This only works if a print area has been setup.

Does that help atall?

Laura GB

replyReplyWed 17 Sep 2008, 15:20Delegate Roy said...

RE: Excel page numbers into variables

Hi Laura,

Thanks for the reply - useful to know but doesn't achieve what I'm trying to do, which is to make sure an index page in a multi page report matches the page numbers Excel will use when it prints it (the greyed 'watermark' that shows when using the page break preview.)

So as Excel knows what page numbers it will use, I'm trying to get it to tell me.

How complex is the way of calculating it?

Roy

replyReplyMon 10 Nov 2008, 08:59Trainer Laura said...

RE: Excel page numbers into variables

Hi Roy

I have found a vba function that will calculate the page numbers. It has a flaw in that it will not recalculate correctly unless you go and edit the cell, but it does work quite well otherwise.


Function PageNumber() As Integer

Dim VPC As Integer
Dim HPC As Integer
Dim VPB As VPageBreak
Dim HPB As HPageBreak
Dim NumPage As Integer

'Decide which way to count thge pages
If ActiveSheet.PageSetup.Order = xlDownThenOver Then
HPC = ActiveSheet.HPageBreaks.Count + 1
VPC = 1
Else
VPC = ActiveSheet.VPageBreaks.Count + 1
HPC = 1
End If

NumPage = 1

'Count the pages up and down
For Each VPB In ActiveSheet.VPageBreaks
If VPB.Location.Column > ActiveCell.Column Then Exit For
NumPage = NumPage + HPC
Next VPB

'Count the pages across
For Each HPB In ActiveSheet.HPageBreaks
If HPB.Location.Row > ActiveCell.Row Then Exit For
NumPage = NumPage + VPC
Next HPB

PageNumber = NumPage

End Function


I hope that helps.

Laura GB

 

 

Please browse our web site to find out more about
microsoft excel training day courses near kent and other Microsoft training courses.

Excel tip:

Filtering Data in an Excel 2010 Worksheet

When you have an Excel Worksheet with masses of data, it's not going to be easy to sift through it. So, in order to view sections of data, you can use the filter tool. Select the cells you want to filter (no need to select the column headers), then click the Home tab on the Ribbon, click Sort and Filter (you will find this in the Editing Section) then click Filter.

You will now see arrows in the top row of all the columns. If you click on an arrow, it will give you some filtering options so you can sort your data into ''Smallest to Largest'' or ''Oldest to Newest'' and so on..

To turn off the filtering, go back to the Home tab and click the Filter button again.

View all Excel hints and tips

forum postHi

I am working with a large spreadsheet that has approx 98000 rows to start.

I have formatted as a table and added auto filters. When I have applied the auto filters there are 24000 cells left visible.

When I attempt to populate or copy paste..

» Forum post: Filtering


Rate this page:
2.2/5 (213 votes cast)
Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses
Microsoft Certified Partner
Security Seal verified by visa, mastercard securecard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Management training

Professional Skills courses
Project Management Course London
Project Management Courses London
Project Management Training London
Project Management Training
Project Seminar
Project Seminars
Time Management Course London
Time Management London
Time Management Courses London
Time Management Training London
Introduction to Finance course
Assertiveness Skills course
Effective Communications Skills training
Presentation Skills London

Training Formats

Public scheduled courses
On-site training
Closed company courses

Consultancy
Application Development

Blogs

Excel Training
MS Project Training
Microsoft Training Blog

Version differences

Office 2010 vs 2007
MS Project version differences

Training Information

London Computer Training
Computer Training London
Docklands Training Courses
Docklands Training London

Training venues London
Client list
FAQ
Pricing and availability
Course details / Syllabus

Training Articles
Training Information

Microsoft training

Microsoft Office training
& IT Applications

Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training
MS Project courses
MS Project training
Outlook courses
PowerPoint courses
PowerPoint training
VBA courses
Word courses
Microsoft.training
(more...)

Excel Training

Excel courses
Excel Training Courses Medway
Autonumber in Excel
Microsoft Excel training
Basic Excel Courses
Basic Excel Course
Basic Excel Training

Interested in MS Access training?

Access courses
Microsoft Access training
Microsoft access courses
Microsoft training access course
Microsoft+access+training
Access courses in london

Training provider

Training providers
IT training companies
IT training providers
Management Training providers
Management Training provider

Event history, feedback results
Events in 2012 · 2011 · 2010 · More

See also

Crystal Reports training