A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi Hsg1,
To achieve your requirement, you may need to use VBA code:
- 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.
- In VBA editor>right-click ThisWorkbook>Insert>Module.
- 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
- Close the editor and return to the sheet.
- 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