Excel 365 VBA command to return the current page number of a sheet

Contributor

Hi
is there an Excel 365 VBA command to return the current page number of a sheet?

Assume I have a sheet with three pages. I want to display the sentence "Page 1 of 3" on the first page, "Page 2 of 3" on the second page, and "Page 3 of 3 " on the third page. I do not want to use the footer. I can count the total pages but how do assign the individual pages.

Regards

1 Reply
I think you are out of luck. Excel maintains a count of sheets. It is this count that gives you the names "Sheet1", "Sheet2" ... Problem is, that count keeps ticking up even as you delete sheets and insert new ones. However, you could program a function that could do i=0 FOR EACH ws in Worksheets i=i+1 if ws.Name = ActiveWorksheet.Name then exit function endif next This is a suggestion off the top of my head. Do not take it literally. ActiveWorksheet.Name is wrong but there is some token to know the cell from which a function is called. (I forget.) Use the Worksheet of that. But I believe that the loop return sheets in the order they are arranged in the Workbook. But I cannot guarantee that either.