Share via

Insert page number in active cell instead of in footer

Anonymous
2017-05-20T06:24:19+00:00

I print a list of persons everyday. Each page has 30 names.

Sheets having employees names a re named as E1, E2, E3 ...etc.

Sheets having contract persons names are named as C1, C2, C3, C4 ...etc.

On days when there are 80 employees  and 100 contract persons, I have seven sheets E1, E2, E3, C1, C2, C3, C4

On days when there are 50 employees and 70 contract persons, I have five sheets E1, E2, E3, C1, C2, C3.

In first case, Sheet C1, when printed, has to show sheet 4/7

In second case, Sheet C1, when printed, has to show 4/6

The lists will vary on day to day basis.

Requirement is to print "page no / out of pages" in the active area on a sheet, and not in header or footer.

How to do this?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

6 answers

Sort by: Most helpful
  1. Anonymous
    2017-05-21T07:07:15+00:00

    Hi Hsg1,

    To achieve your requirement, you may need to use VBA code:

    1. Open the Excel sheet>click Developer ribbon>Visual Basic. To add the Developer ribbon, click File>Options>Customize Ribbon>select Developer in the right panel.
    2. In VBA editor>right-click ThisWorkbook>Insert>Module.
    3. Copy and paste the following VBA code

    Sub pagenumber()

    'updateby Extendoffice 20160506

        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

        Else

            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

        Next

        For Each xHPB In ActiveSheet.HPageBreaks

            If xHPB.Location.Row > ActiveCell.Row Then Exit For

            xNumPage = xNumPage + xVPC

        Next

        ActiveCell = "Page " & xNumPage & " of " & Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")

    End Sub

    1. Close the editor and return to the sheet.
    2. Select a cell where you want to insert page number. Click Developer>Macros>select that macro>Run. You will see the page number is inserted to that cell.

    Best regards,

    Tim

    100+ people found this answer helpful.
    0 comments No comments
  2. Vijay A. Verma 104.8K Reputation points Volunteer Moderator
    2017-05-23T13:33:35+00:00

    Seems you want to show the sheet sequence and total number of sheets. In this case, you can put following as =ShowPage() in a sheet and it will show you 4/7 or 4/6 kind of things.

    Function ShowPage()

        Application.Volatile

        ShowPage = Application.Caller.Worksheet.Index & "/" & Worksheets.Count

    End Function

    If these are pages, then you can accomplish the same through a small VBA code but this will not be a Function but a Sub and can write in an appropriate cell. Let the group know if this is the requirement.

    20+ people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2017-05-20T12:07:53+00:00

    Showing page number/no. of pages using Header / Footer is known.

    Requirement is to show it inside active portion of worksheet, not header or footer.

    Does your reply mean, using formula etc. ; we can not show page numbers on active portion of worksheet?

    regards,

    20+ people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2017-05-22T17:53:53+00:00

    The code gives "page 1 of 1" in each worksheet.

    I have six or seven worksheets, where I have one page each and want to print them

    one after other in a report. In case of 7 sheets, the display should be "page 1 of 7",

    "page 2 of 7" etc...

    10+ people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2017-05-20T06:43:17+00:00

    Does this help: Insert page numbers on worksheetsNote: If you want numbers shown on pages when you print a Microsoft Excel worksheet, you can insert page numbers in the headers or footers of the worksheet pages. Page numbers that you insert are not displayed on the worksheet in Normal view— they are shown only in Page Layout view and on the printed pages.

    3 people found this answer helpful.
    0 comments No comments