Get number of pages in excel

/Excel Tips /Formula To Count The Number Of Sheets In The Excel

Excel Headings Without Merging Cells

In fact, MS Excel doesn’t have any Straight Formula to Count the Number of Sheets in the Workbook. But, we have Indirect Way to Count the same.

HOW?

First we need to “Define Name” by Referring to =GET.WORKBOOK(1)&T(NOW())

Then, Use the below Formula to Count the Number of Sheets

=COUNTA(INDEX(DEFINED NAME,0))

Step By Step?

2003 and Below excel versions

1. Click ”Ctrl+F3′, then ‘Define Name’ Box appears
2. Enter ‘Names in workbook’ as CountSheets (Your choice)
3. Enter ‘Refers To’ as =GET.WORKBOOK(1)&T(NOW())
4. Click OK
5. Come to the Cell, where you want to enter the Formula
6. Enter the Formula as =COUNTA(INDEX(CountSheets,0))
7. Click Enter

2007 and above Excel Versions

1. Click ‘Ctrl+F3’, then ‘Name Manager’ Box Appears
2. Click ‘New’ (use shortcut key Alt+N)
3. Then, ‘New name’ box appears
4. Enter ‘Name’ as “CountSheets(Your choice)
5. Enter ‘Refer To’ as =GET.WORKBOOK(1)&T(NOW())
6. Click OK
7. It takes you to the ‘Name Manager’ box again (you can find the Defined Name in the list)
8. Click ‘Close’

9. Come to the Cell, where you want to enter the Formula
10. Enter the Formula as =COUNTA(INDEX(CountSheets,0))
11. Click Enter

If you google on this, you can find alternative solutions with VBA code. Without using VBA, I think this is the easy way to Count Number of Sheets.

Don’t forget to give comment below, if you find any alternative solution, or if you have any questions.

Also read

  • How to Count Number of Rows in a Word Table?
  • Why INDEX-MATCH Is Far Better Than VLOOKUP or HLOOKUP in Excel

Courtesy: lostinexcel.blogspot.in

Related

This post will guide you how to count the number of sheets in a workbook in Excel. How do I count the number of worksheets in a workbook with VBA Macro in Excel.

  • Count the Number of Sheets with Define Name
  • Count the Number of Sheets with VBA Macro
  • Video: Count the Number of Sheets

Count the Number of Sheets with Define Name


If you want to count the number of worksheets in a given workbook in Excel, you can use the Defined Name and a Formula to achieve it. Just do the following steps:

 #1 go to Formula tab, click Define Name command under Defined Names group, and the New Name dialog will open.

 count worksheet number1

#2 type one defined name in the Name text box, such as: countWorksheets, and then type the formula =GET.WORKBOOK(1)&T(NOW()) into the text box of Refers to. Click Ok button.

count worksheet number2

#3 Type the following formula based on the COUNTA function and the INDEX function to get the number of worksheets in the current workbook. And press Enter key in your keyboard, you will get the number of worksheets in your workbook.

=COUNTA(INDEX(CountWorksheets,0))

    count worksheet number3   

Count the Number of Sheets with VBA Macro


You can also use an Excel VBA Macro to get the number of worksheets in the current workbook. Just do the following steps:

#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

#2 then the “Visual Basic Editor” window will appear.

#3 click “Insert” ->”Module” to create a new module.

convert column number to letter3

#4 paste the below VBA code into the code window. Then clicking “Save” button.

count worksheet number4

Sub CountWorkSheets()
    MsgBox "The number of worksheets in the current workbook is : " & Application.Sheets.Count
End Sub

#5 back to the current worksheet, then run the above excel macro. Click Run button.

count worksheet number5

#6 let’s see the result:

count worksheet number6

Video: Count the Number of Sheets

Asked
10 years, 8 months ago

Viewed
543 times

I’m not looking for the number of worksheets. I’m looking for the total number of pages within each Worksheet.

S3ddi9's user avatar

S3ddi9

2,0912 gold badges19 silver badges34 bronze badges

asked Aug 6, 2012 at 21:39

John Smith's user avatar

1

this is how you can get it

ActiveSheet.PageSetup.Pages.Count

answered Aug 6, 2012 at 21:43

S3ddi9's user avatar

S3ddi9S3ddi9

2,0912 gold badges19 silver badges34 bronze badges

1

Working with large Excel files with many worksheets can be frustrating. Especially finding things and keeping an overview is troublesome. One (small) feature might come in handy: See the sheet number of the current worksheet and the total number of worksheets. For example, like this: “Sheet 5 / 12”. You can enable this with just a click in the Status Bar.

What the “Sheet Number” feature does

The sheet number feature in Excel does the following:

Show the current sheet number and total number of worksheets in the bottom-left corner of the Excel window.

Display the current sheet number and total number of worksheets in the bottom-left corner of the Excel window.
  • It shows the number of the worksheet that is currently selected in the Status Bar in the left-bottom corner of the Excel window.
  • The sheets are counted from left to right. So, if you move a worksheet the numbering changes accordingly (don’t mix it up with the sheet names in the background, for example “Sheet1” etc.).
  • It also shows the total number of worksheets in the current Excel file.
  • Hidden and very hidden sheets are regarded in the total number count.
  • When you select multiple worksheets, still the number of the currently active worksheet is shown.
  • When you click on the Sheet Number, the Navigation Pane opens. The current worksheet is then highlighted (with bold font) in the Navigation Pane.

Availability of the feature in Excel

As of now (August 2021), this feature is not available for everyone. Probably, it will sooner or later be rolled out to every user.

  • The feature to display the sheet number is first introduced in Excel version 2108 (so the release of August 2021) with Office 365 (now Microsoft 365).
  • Initially, the sheet number feature is only available for Office Insider subscribers (for those users who test “beta” versions – not the majority of Excel users). Usually within the next months it’s also available for regular Office 365 subscribers.
  • It is at first only available in Office for Windows (not Mac or Office Web / Online).
Show the sheet number in Excel by right-clicking on the status bar and then on "Sheet Number".
Show the sheet number in Excel by right-clicking on the status bar and then on “Sheet Number”.

After knowing now what this feature does and who can use it, it’s time for activating it:

  1. Right-click on the status bar.
  2. Set the checkmark at “Sheet number”. Again, if you don’t see such entry please read the section above.

That’s it, now you should see something like “Sheet 3 of 12” in the bottom-left corner of the Excel window.

Alternatives

Total number of sheets (and more) in the “Workbook Statistics”

Excel has another function, called “Workbook Statistics”. It shows very similar information (although not the current worksheet number). It is available already on Windows, Mac and the web version of Excel.

You can activate it by right-clicking on the status bar and then on “Workbook Statistics”.

"Workbook Statistics" shows a summary of the Excel file.

“Workbook Statistics” shows a summary of the Excel file.

Worksheet overview with an Excel Add-In

Because keeping an overview of the workbook is especially for larger Excel files difficult, we have integrated several features into our Excel add-in “Professor Excel Tools”. For example, the “Sheet Manager”, which provides a simple and powerful summary of all your worksheets.

"Professor Excel Tools" has a powerful worksheet manager.

“Professor Excel Tools” has a powerful worksheet manager.

Professor Excel Tools Box

This function is included in our Excel Add-In ‘Professor Excel Tools’

(No sign-up, download starts directly)


Image by Renate Köppel from Pixabay

Henrik Schiffner is a freelance business consultant and software developer. He lives and works in Hamburg, Germany. Besides being an Excel enthusiast he loves photography and sports.

  • #1

As I have multiple Excel files within multiple different folders. I want to know how I can count the number of pages of each file within all the relevant folders without opening all the files individually. A I have over 300 Excel files that I need this done to.

Ideally I don’t want to use a Macro where possible. But if required I will.

Thanks for your help & continued support

Hui

Hui

Excel Ninja


  • #2

Amar

Firstly, Welcome to the Chandoo.org Forums

Do you mean Worksheets in each Workbook or Print Pages

  • #3

Amar

Firstly, Welcome to the Chandoo.org Forums

Do you mean Worksheets in each Workbook or Print Pages

Hey Hui, I mean Print Pages. Any suggestions?
Thanks

Hui

Hui

Excel Ninja


  • #4

No
Evan a macro will have to loop through each file in the directory and open it to achieve what you want

The Number of Worksheets or Print Pages is not shown in the Windows Explorer File Properties which was going to be my next suggestion of where to look

  • #5

No
Evan a macro will have to loop through each file in the directory and open it to achieve what you want

The Number of Worksheets or Print Pages is not shown in the Windows Explorer File Properties which was going to be my next suggestion of where to look

Hey Hui, even if the Macro needs to open up each file, then that’s totally fine.

What would the Macro Code be for this problem. Please note that I want the Print Pages Count for ALL the worksheets within a Workbook. But I only need one total for the workbook not for each individual worksheet.

Hui

Hui

Excel Ninja


  • #6

Run this file and see if it does what you want

  • 18.7 KB
    Views: 14

  • #7

Hey Hui, thanks for this, this is really awesome.

1) However the Number of Print Pages is usually incorrect. As I need to have the «Print Entire Workbook» number of Print Pages to be displayed. Refer to the attached image for details.

2) Also it currently only works with XLS files, but I need to run the Macro of CSV and XLSX file formats as well.

Thanks for your continued support Hui, I really appreciate it.

  • Image.png

    36.2 KB
    Views: 8

Hui

Hui

Excel Ninja


  • #8

It processes 3 file types for me

upload_2017-9-13_23-0-16.png

I’m not sure how accurate CSV Files will be as they contain no page settings and hence will default to the Local Default Printer and default font sizes and default margins etc, all which change the page layout

  • 19.1 KB
    Views: 11

  • #9

Thank you for this Hui, I really appreciate it, it does work.

Your a Genius

Hui

Hui

Excel Ninja


  • #10

The issue with CSV Files is that they will default to the Default font and font size and page borders
They could be included if you really wanted that

  • #11

Hey Hui,

I have been using the file for a few days without any problems. Once again, thanks for everything.

But I have realized that once I run the Macro and it opens a «Read Only» file, the Macro doesn’t work.

Any suggestions on how to make it work with «Read Only» Files?

If not then I am happy for it to skip that file and proceed to the next available file. But at the current moment it just stops and does not skip to the next available file.

Your help is greatly appreciated.

Any other suggestions are most welcomed.

Best Regards,
Amar

  • #12

Hi !

Explain first why the file is Read Only ?

  • #13

Hey Marc,

Thanks for helping out.

In fact don’t worry about the Read Only files.

I actually have another problem that I discovered.

PROBLEM:

When a Workbook has multiple Worksheets what happens is that the Macro populates the Page Count for the first Worksheet times by the number of worksheets within the Workbook. So it does not actually calculate the total Page Count for the entire workbook.

For example

If a workbook has 5 worksheets and the page count on the first worksheet is 10 pages. The Macro will populate the page count as 50 pages (5 * 10) rather than counting the actual Page Count among all the pages.

Your help is greatly appreciated.

Thank you

Hui

Hui

Excel Ninja


  • #14

Can you please replace the code in the file with the code below

Code:

Sub File_Deatils()

  Dim fldr As FileDialog
  Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
  With fldr
  .Title = "Select a Folder"
  .AllowMultiSelect = False
  .InitialFileName = Application.DefaultFilePath
  If .Show <> -1 Then GoTo 10
  sItem = .SelectedItems(1)
  End With

10: path = sItem & "*.xls*"
  Cells.ClearContents

  cdir = path
  
  Sheet1.Name = "Excel File Details"
  Sheet1.Range("A1") = sItem
  
  Sheet1.Range("A3") = "No."
  Sheet1.Range("B3") = "File Name"
  Sheet1.Range("C3") = "No of Worksheets"
  Sheet1.Range("D3") = "No of Print Pages"
  
  Dim tgt As Worksheet, r As Long
  Set tgt = Sheet1
  r = 0
  
  Dim f As String
  f = Dir(path)
  
  Dim wb As Workbook, ws As Worksheet
  Dim iTotPages As Integer
  
  Do Until f = ""
  If f <> ThisWorkbook.Name Then
  Set wb = Workbooks.Open(sItem & "" & f, ReadOnly:=True)
  
  r = r + 1
  
  iTotPages = 0
  
  For Each ws In wb.Sheets

  ws.Activate
  iTotPages = iTotPages + ActiveSheet.PageSetup.Pages.count
  
  Next
  
  tgt.Cells(r + 3, 1) = r
  tgt.Cells(r + 3, 2) = wb.Name
  tgt.Cells(r + 3, 3) = wb.Worksheets.count
  tgt.Cells(r + 3, 4) = iTotPages
  
  wb.Close savechanges:=False
  End If
  f = Dir()
  Loop

MsgBox r & " : files found in folder"

End Sub

If you still have troubles please post a sample file which causes errors

Last edited: Sep 20, 2017

  • #15

Hey Hui,

Thanks for the above file.

Now the Page Count for Workbooks with Multiple worksheets finally works. Happy Days.

But now some of the Workbooks with a single worksheet are incorrect.

If possible please arrange to resolve this problem regarding the wrong page count for some single page workbooks.

Unfortunately I am unable to provide you with some sample files, this is due to the confidential nature of the files I am dealing with, sorry.

Once again, thank you for your continued support Hui

  • #16

Hey Hui,

<snip>

Unfortunately I am unable to provide you with some sample files, this is due to the confidential nature of the files I am dealing with, sorry.

Once again, thank you for your continued support Hui

Sanitize them by replacing the proprietary information with junk. It’s very hard for even Ninjas to fix problems that are described via a third party — it can be an awful waste of their effort going down ratholes ..

Hui

Hui

Excel Ninja


  • #17

Amar

can I please ask that you check your files as I cannot replicate the issue

If you open the file
Then click on the Page Break Preview at the lower right corner of Excel
Then look for small slithers of Page 2 as either:

A Vertical slice or
upload_2017-9-29_14-50-58.png

A Horizontal slice
upload_2017-9-29_14-53-10.png

My code works when there is only a single page:
upload_2017-9-29_14-54-25.png

Different printer drivers print out the document with different numbers of rows and columns. When we need to print an excel file with header and footer, the information of how many pages in one excel file and where is the first line start becomes very important. This article will show you how to get the page count of excel file and the row and column number of page break in C# by using Spire.XLS for .NET.

Firstly, make sure that Spire.XLS for .NET (version7.3.12 or above) has been installed on your machine. And then, adds Spire.XLS.dll as reference in the downloaded Bin folder thought the below path: «..Spire.XLSBinNET4.0 Spire.XLS.dll».

Now it comes to the details of how to get the page count of excel file in C#:

//Create a new excel document
Workbook wb = new Workbook();
//load from the file
wb.LoadFromFile(@"D:test.xlsx");
//get the page info.
var pageInfoList = wb.GetSplitPageInfo();
//Get the sheet count
int sheetCount = pageInfoList.Count;
//The page count of the first sheet
int pageCount = pageInfoList[0].Count;

You could find a screenshot shows row number and column number of each Excel page.

Get the page count of excel file

Spire.XLS for .NET, as a professional Excel component, it enables you to generate, read, write and manipulate Excel files in C#, VB.NET in any .NET applications directly.

I have 100+ sheets, it is hard for me to count them one by one.

Is there a one line formula to get the total number of sheets? The CELL or ADDRESS function perhaps?

I remember using something like this once, but I cannot seem to remember it.

Thank you.

Andi Mohr's user avatar

Andi Mohr

4,1704 gold badges31 silver badges46 bronze badges

asked Jun 25, 2014 at 5:18

user338420's user avatar

Here is a neat, formula-based solution.

  1. Create a New Name in Name Manager called wshNames, with the value:
    =RIGHT(GET.WORKBOOK(1),LEN(GET.WORKBOOK(1))-FIND("]",GET.WORKBOOK(1)))

  2. In any cell you want to show the number of worksheets, enter: =COUNTA(wshNames)

enter image description here

Note: Step 1 relies on an XLM formula. More on this here — note you will need to save as a .xlsm. This technique is borrowed from David Hager, via this.

Community's user avatar

answered Jun 25, 2014 at 8:40

Andi Mohr's user avatar

Andi MohrAndi Mohr

4,1704 gold badges31 silver badges46 bronze badges

you have to use a little bit of VB for that.

Try for «Table sheets -> without Diagrams»

Public Sub test()
    MsgBox ThisWorkbook.Worksheets.Count
End Sub

Try for «All Sheets» -> including Diagrams

Public Sub test2()
    MsgBox ThisWorkbook.Sheets.Count
End Sub

CharlieRB's user avatar

CharlieRB

22.5k5 gold badges55 silver badges104 bronze badges

answered Jun 25, 2014 at 7:10

jofro's user avatar

jofrojofro

461 bronze badge

1

You can easily use the sheets formula, in any empty cell you can type
=SHEETS()
and that’s it. it will count all the sheets in the workbook.

Reddy Lutonadio's user avatar

answered Sep 19, 2020 at 15:57

user1220941's user avatar

Insert a module in the workbook of which you want to count the total number of sheets of.

Then copy in the below code and hit run

    Public Sub CountWorksheets()
       MsgBox "Total Sheets count:" & Application.Sheets.Count
    End Sub

You’ll get a relevant output:

click the link to see the screenshot

PeterH's user avatar

PeterH

7,33719 gold badges53 silver badges80 bronze badges

answered May 30, 2018 at 10:40

Vickar's user avatar

VickarVickar

1313 bronze badges

Понравилась статья? Поделить с друзьями:
  • Get number of column excel
  • Get number of cells excel
  • Get number from excel cell
  • Get my tongue round this word
  • Get months in excel