Forum Discussion
ajl_ahmed
Jul 14, 2022Iron Contributor
Excel 365 VBA command to return the current page number of a sheet
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...
ecovonrein
Jul 16, 2022Iron Contributor
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.