A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi Kar Fung,
Your screenshot makes it clear. If you want something like that, let's use small VBA funtion:
- Press Alt + F11 and Choose: Insert > Module Then paste this code: Function PrintedPageNumber() As String
End FunctionDim ws As Worksheet Dim i As Long Dim PageNo As Long Dim TotalPages As Long Dim HPages As Long Dim VPages As Long Application.Volatile 'Current worksheet Set ws = Application.Caller.Worksheet 'Calculate page breaks ws.DisplayPageBreaks = True HPages = ws.HPageBreaks.Count + 1 VPages = ws.VPageBreaks.Count + 1 'Pages before the current worksheet PageNo = 0 For i = 1 To ws.Index - 1 Worksheets(i).DisplayPageBreaks = True PageNo = PageNo + _ (Worksheets(i).HPageBreaks.Count + 1) * _ (Worksheets(i).VPageBreaks.Count + 1) Next i 'Find the page containing the cell Dim r As Long Dim c As Long r = Application.Caller.Row c = Application.Caller.Column PageNo = PageNo + 1 For i = 1 To ws.HPageBreaks.Count If ws.HPageBreaks(i).Location.Row <= r Then PageNo = PageNo + VPages Else Exit For End If Next i For i = 1 To ws.VPageBreaks.Count If ws.VPageBreaks(i).Location.Column <= c Then PageNo = PageNo + 1 Else Exit For End If Next i 'Total pages in the workbook TotalPages = 0 For i = 1 To ThisWorkbook.Worksheets.Count With ThisWorkbook.Worksheets(i) .DisplayPageBreaks = True TotalPages = TotalPages + _ (.HPageBreaks.Count + 1) * _ (.VPageBreaks.Count + 1) End With Next i PrintedPageNumber = PageNo & " / " & TotalPages - Put the formula in your cell. In the cell where your screenshot currently shows 2 / 5, enter: =PrintedPageNumber()
It should display something like: 1 / 5 Then, when the cell is on the next printed page, it will show: 2 / 5 and when you use the same formula in the corresponding cell on another worksheet, the numbering continues rather than starting again at 1. One thing to check, because this is based on printed pages, make sure your sheets already have the correct: Page Layout > Size Page Layout > Orientation Page Layout > Margins Page Layout > Scale/Width/Height Print Area Otherwise Excel may calculate a different number of pages than you expect. Also, if you want the display to look exactly like your screenshot, you can simply use the code: ="Page: "&PrintedPageNumber() which will give: Page 2/5 If your workbook has exactly the same "Sheet: x / y" cell in the same location on every worksheet.
Regards,
Jhun