Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Printing a Worksheet List.

Printing a Worksheet List

by Allen Wyatt
(last updated January 16, 2017)

17

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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2216) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Printing a Worksheet List.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Out of Kilter Borders

Borders not printing properly? It could be any one of a number of reasons causing the problem. This tip provides some ...

Discover More

An Automatic Two Spaces after a Period

Should you put two spaces after a sentence or just one? Ask different people and you will get different answers. To Word the ...

Discover More

Determining the Upper Bounds of an Array

When working with variables in a macro, you may need to know the upper boundary dimension for an array. This can be ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Printing Only Selected Pages

When you print a worksheet, you don't need to print the whole thing. You can print only the pages you want. Here's how to do ...

Discover More

Adding Page Borders to a Printout

Need a full-page border on your Excel printouts? It's not as easy to get one as you might wish. There are a few ways you can ...

Discover More

Printout Doesn't Match Display for Some Cells

Have you ever noticed that when you print something, there are times that what is printed doesn't exactly match what you see ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six more than 8?

2016-07-17 05:29:28

Barry

@Peter,

There are two different threads covering your topic. May I suggest looking at these threads as a starting point for what you want to do.

http://excel.tips.net/T002145_Dynamic_Worksheet_Tab_Names.html
http://excelribbon.tips.net/T007993_Dynamic_Worksheet_Tab_Names.html


2016-07-16 14:01:36

Peter Ellison

Hi thanks, this works perfectly.

Is there anyway of doing the opposite? Having a list of titles and then using code to insert the automatically into worksheet title tab?


2016-05-17 02:12:00

Oliver

i read 8 of these before i came across this one and it was the easiest by far.
Thank you


2015-06-05 14:52:38

KJ Freeman

You are my HERO today!!
Thank you!!!!


2015-01-29 15:11:09

CharlesHarris

Thanks for all the updates and info. Great work.
Charlie


2015-01-28 06:22:54

Dave K

@Willy

I put the VBA code from the Mr. Excel site into my PERSONAL.XLSB and assigned a shortcut key. It works a treat!

Thanks for sharing the information.


2015-01-27 11:34:30

Willy Vanhaelen

You will find the answer here: http://www.mrexcel.com/forum/excel-questions/418196-how-follow-hyperlink-keyboard.html


2015-01-27 07:13:34

Dave K

@Willy Vanhaelen

Willy, this is a wonderful bit of code! Many thanks for your help.

Question:
By any chance would you know how to fix a small problem? I am using Office 2010 on Windows 7 Enterprise. When I create a hyperlink, either manually or using your macro, I must use the mouse to click on the link to go to the destination. Previously, in Excel 97, I merely had to go to the cell containing the link and press Enter or Return to get there.

Any ideas how I can get the Enter/Return key to work in 2010?


2015-01-26 10:27:02

Willy Vanhaelen

@Charles Harris: Here it is:

Sub MakeHyperlinkIndex()
Dim ndx As Worksheet, X As Integer
Set ndx = Sheets.Add(before:=Sheets(1))
ndx.Name = "Index"
ndx.Cells(1) = "Worksheets"
For X = 2 To Worksheets.Count
ndx.Hyperlinks.Add _
Anchor:=ndx.Cells(X, 1), Address:="", _
SubAddress:="'" & Worksheets(X).Name & "'!A1", _
TextToDisplay:=Worksheets(X).Name
Next X
End Sub

The macro creates a new worksheet to deal with the overwriting risk.
Refer to Barry Fitzpatrick's macro (4 Dec 2013) if you want to avoid an error when the sheet already exists.


2015-01-26 04:33:55

Dave K

@Charles

Here is a small change to my code which will give you a solution. While it's not quite what you want, it works. I don't yet know how to insert a proper hyperlink.

The code produces a list of sheets as before, but each entry is a formula-based link to Cell A1 of the other sheets. If you put the sheet name into Cell A1 of each sheet, then you get a meaningful list. Double-click on the sheet name in the list just created and you will be brought to that sheet.

Notes:
1. The code Cells(1, 1) refers to Cell A1. Change the Row and Column values if you prefer to have your sheet names elsewhere.

2. You will need to uncheck the option to "Edit directly in cells" for the double-click to work.

3. The screenupdating setting stops the flicker when Excel selects each sheet in the workbook.

4. I would recommend that you include a check to make sure that existing data is not over-written, for example by not properly selecting a blank column before you run the macro.

Anyway, here is my amended code.
Dave.


Sub InsertLinks()
Dim j As Integer
Dim NS As Integer
Dim C As Integer
Dim sht As Worksheet
NS = Sheets.Count
C = ActiveCell.Column
Set sht = ActiveSheet

Application.ScreenUpdating = False
For j = 1 To NS
Sheets(j).Activate
Cells(1, 1).Select
Selection.Copy
sht.Activate
Cells(j, C).Select
ActiveSheet.Paste link:=True
Next j
Application.ScreenUpdating = True
End Sub


2015-01-23 20:27:39

Charles Harris

Hi

With code dated 8 Oct 2012 is it possible to make the list with each item hyper linked to the specific sheet ?

Thanks


2013-12-05 06:16:34

Dave Kerr

@Barry
Thanks for the tip about the sheet numbers. I didn't know how Excel handled them.
Neat solution too, thanks.


2013-12-04 05:59:44

Barry Fitzpatrick

Here's an alternative that adds a sheet and names it "Sheet Names" to avoid any overwriting issues:

Sub List_of_Sheet_Names()

Dim Number_of_Sheets As Integer
Dim Row As Integer
Dim Column As Integer
Dim j As Integer
Dim shtList As Worksheet

'Delete an existing sheet named "Sheet Names"
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Sheet Names").Delete
Application.DisplayAlerts = True
On Error GoTo 0

'create and name a new sheet, and position it at the far left
Set shtList = Worksheets.Add(Before:=Sheets(1))
shtList.Name = "Sheet Names"

Number_of_Sheets = Sheets.Count
'make the list of sheet names
For j = 2 To Number_of_Sheets
shtList.Cells(j - 1, 1) = Sheets(j).Name
Next j

End Sub

NB if there is already a sheet named "Sheet Names" (e.g. if you've run the macro once already). then it will be deleted.

Note also the use of the "Before" parameter. This is because Excel sheet index number is in the order of the sheet tabs on the workbook itself i.e. the leftmost sheet tabs has index 1. The "Before" parameter positions the new sheet at the far left and so is not listed in the list of worksheets.


2013-12-04 05:57:05

Dave Kerr

I went a little further and had the macro check that there are no currently filled cells in the range about to be occupied by the listing.

Excluding the declaration of variables, which should be fairly apparent, here is the code that I use now. It works well for me.

NS = Sheets.Count
R = ActiveCell.Row
C = ActiveCell.Column
NonBlank = 0

For j = 1 To NS
If Cells(R, C) <> "" Then
NonBlank = NonBlank + 1
End If
R = R + 1
Next j

R = ActiveCell.Row

If NonBlank > 0 Then
MsgBox "This process will over-write existing cells." & vbCrLf & _
"Please select an area of blank cells and re-start." & vbCrLf & _
"Click OK to stop."
Exit Sub
Else
For j = 1 To NS
Cells(R, C).NumberFormat = "@"
Cells(R, C) = Sheets(j).Name
R = R + 1
Next j
End If


I hope this helps!
Dave


2013-12-03 08:33:56

Chris

Thanks for this. Its just the start I needed to get what I want!

Altered it slightly and now the macro inserts the list of worksheets in the cell you pick.

Sub List_of_Sheet_Names()

Dim Number_of_Sheets As Integer
Dim Row As Integer
Dim Column As Integer
Dim j As Integer

Number_of_Sheets = Sheets.Count
Row = ActiveCell.Row
Column = ActiveCell.Column

For j = 1 To Number_of_Sheets
Cells(Row, Column) = Sheets(j).Name
Row = Row + 1
Next j

End Sub


2012-10-08 05:10:58

Barry Fitzpatrick

I would recommend in both of the above examples to clearing the column that will be used to store the sheet names, because if there is already data in the column that doesn't get overwritten by the macro then it will appear that there are more sheets than there actually are. Any subject macro where it to use the data in the column would give a run time error as it wouldn't be able to find the sheets at the end of the list (i.e. those entries that were not overwritten).


2012-10-08 03:33:58

Dave K

Brilliant in its simplicity. Just add two lines and make one small change if you want to decide which column to use, as follows.

Sub GetSheets()
Dim j As Integer
Dim NS As Integer
Dim C As Integer

NS = Sheets.Count
C = ActiveCell.Column

For j = 1 To NS
Cells(j, C) = Sheets(j).Name
Next j

End Sub

Before you run the macro, select any cell in the column where you want the list to appear. The column value from ActiveCell is assigned to the variable C and used in the positioning loop.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.