Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Printing a Worksheet List

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.

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.

Related Tips:

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

 

Comments for this tip:

KJ Freeman    05 Jun 2015, 14:52
You are my HERO today!!
Thank you!!!!
CharlesHarris    29 Jan 2015, 15:11
Thanks for all the updates and info. Great work.
Charlie
Dave K    28 Jan 2015, 06:22
@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.
Willy Vanhaelen    27 Jan 2015, 11:34
You will find the answer here: http://www.mrexcel.com/forum/excel-questions/418196-how-follow-hyperlink-keyboard.html
Dave K    27 Jan 2015, 07:13
@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?

Willy Vanhaelen    26 Jan 2015, 10:27
@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.
Dave K    26 Jan 2015, 04:33
@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
Charles Harris    23 Jan 2015, 20:27
Hi

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

Thanks
Dave Kerr    05 Dec 2013, 06:16
@Barry
Thanks for the tip about the sheet numbers. I didn't know how Excel handled them.
Neat solution too, thanks.
Barry Fitzpatrick    04 Dec 2013, 05:59
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.
Dave Kerr    04 Dec 2013, 05:57
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
Chris    03 Dec 2013, 08:33
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

Barry Fitzpatrick    08 Oct 2012, 05:10
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).
Dave K    08 Oct 2012, 03:33
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.

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 4+5 (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2015 Sharon Parq Associates, Inc.