In complex workbooks that contain many worksheets, it is not unusual to need a list of the different worksheets. Once you have the list, you can print it or use it in some other fashion, such as to create a table of contents for your workbook. The following macro, GetSheets, quickly retrieves the names of the worksheets in the current workbook. It places them in the current worksheet, starting at cell A1 and then working downwards.
Sub GetSheets() Dim j As Integer Dim NumSheets As Integer NumSheets = Sheets.Count For j = 1 To NumSheets Cells(j, 1) = Sheets(j).Name Next j End Sub
This macro will overwrite anything in a cell it needs in the current workbook, so you should make sure you don't need anything in column A of the worksheet. If you don't want to overwrite anything, make sure you create a new worksheet and then run the macro from that worksheet.
Once the list of worksheets is created, you can format it as desired, and then print it out.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12181) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Printing a Worksheet List.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Got a bunch of worksheets and you want to save paper by printing multiple worksheets on a single piece of paper? There ...
Discover MoreHave you ever wanted to do a simple printout, only to find that Excel spit out dozens of pages, and most of them were ...
Discover MoreWant to make sure that when you worksheet is printed that everything in the workbook is really printed? You can ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-11-30 11:22:07
Frederick Rothstein
@Alex, Philip, Tony (and anyone else reading this),I know this is some three years late, but you may find the "Neat Go To Selector" I posted in my mini-blog to be of some interest...http://www.excelfox.com/forum/showthread.php/1830-A-Neat-quot-Go-To-Sheet-quot-Selector?highlight=neat
2016-09-02 12:08:16
Tony O
Further to my previous post, I have now found out where I went wrong and now everything works fine. I had missed a ' sign out and typed "" and not "'".
2016-09-02 09:15:49
Tony O
Thank you for this tip.
I have added the following command which will make sure that the results will always be in the tab called Index
Worksheets("Index").Activate
Alex B's addition works well except I have some tab names that contain spaces and so the links to these tabs do not work. i.e. Tab data.
Is there a way to have the hyperlink adapt the tab name to match what it is expecting?
2016-09-02 00:09:44
Philip
One useful extension of this code is to embed it into a worksheet that you might call "Index" and have it refresh each time the Index sheet activates. Then, by copying this Index sheet into any workbook you have, you get an automatic indexing sheet in a couple of mouse clicks ...
2016-08-27 21:10:27
Alex B
I'm sure this is not the most elegant code but if you replace
Cells(j, 1) = Sheets(j).Name
With the following 2 lines of code, the list will have hyperlinks back to each of the sheets in the list (goes to cell A1)
strSheetName_Addr = "'" & Sheets(j).Name & "'!A1"
ActiveSheet.Hyperlinks.Add anchor:=Cells(j, 1), Address:="", SubAddress:=strSheetName_Addr, TextToDisplay:=Sheets(j).Name
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments