Excel 2010-2019
Excel 2007
Excel 2003
Tips & Tricks
Excel Forum
Course Index CIG Excel Book
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
Home > Forums > Excel
Excel Forum

Back to Excel Forum

Page 1 5 Upload Images   Link  
Bruno Segers 
10 months ago
Hey guys,

Is there a formula or VBA code in Excel that can indicate in a cell how many pages of the so many pages in a specific sheet consists of?
Don't give me any comment to put it in de footer of header please. That i now how to do it.
Bruno from Belgium.
Bruno Segers
10 months ago
This code does show the correct number of pages, but when printing, it stops its function on the following pages. Is there anyone who can help me further? I have attached the print preview and file.

Option Explicit

Sub Pagenumber()
    Dim xVPC As Integer
    Dim xHPC As Integer
    Dim xVPB As VPageBreak
    Dim xHPB As HPageBreak
    Dim xNumPage As Integer
    xHPC = 1
    xVPC = 1
    If ActiveSheet.PageSetup.Order = xlDownThenOver Then
        xHPC = ActiveSheet.HPageBreaks.Count + 1
        xVPC = ActiveSheet.VPageBreaks.Count + 1
    End If
    xNumPage = 1
    For Each xVPB In ActiveSheet.VPageBreaks
        If xVPB.Location.Column > ActiveCell.Column Then Exit For
        xNumPage = xNumPage + xHPC
    For Each xHPB In ActiveSheet.HPageBreaks
        If xHPB.Location.Row > ActiveCell.Row Then Exit For
        xNumPage = xNumPage + xVPC
    ActiveCell = "REV 1 - Strona " & xNumPage & " - " & Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
End Sub
Richard Rost
10 months ago
Hi Bruno. It's been a while since I've done anything like this with Excel VBA (Access is my forte). However, if memory serves you can calculate the number of printed pages in a Worksheet with:


Also, please review the Forum Rules. I don't allow the posting of external links.

This thread is now closed. If you wish to comment, start a NEW discussion, below.

Back to Excel Forum Comments

Start a NEW Conversation
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.

You may want to read these articles from the 599CD News:

6/30/2022Sales Chart
6/17/2022Fast AutoSum
2/22/2022ISO Date Format
1/27/2022Work Days
1/11/2022Excel Fast Tips
1/7/2022Count Cells by Color
1/7/2022Excel VBA
1/7/2022Excel Count by Color
12/26/2021Conditional Formatting
12/9/2021Excel 2003 Quick Start 1

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
My Account
My Courses
Lost Password
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Customer Support
Web Site Tour
Consulting Services
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Contact Info
Support Policy
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn