You are on page 1of 2

LIST THE NAMES OF WORKSHEETS

In some instances, it is useful to be able to determine and list the names of the worksheets in your Excel workbooks. For example, you might want to create an index to catalog the worksheets in your workbook. You could then store the results in a separate worksheet. That way, you can quickly find the location of a particular worksheet. Try it: 1. Start Excel. A new, blank workbook appears. 2. Add a command button to the worksheet:

Select Sheet1. On the View menu, point to Toolbars, and then click Control Toolbox. Click the Command Button button. Click somewhere on the worksheet to insert the command button, and then click and drag the borders of the command button to size it.

3. Now, add Visual Basic code to the command button:

Right-click the command button, and then click View Code on the shortcut menu.

In the Microsoft Visual Basic Editor, enter the following code between the Private Sub CommandButton1 statement and the End Substatement:

Set NewSheet = Sheets.Add(Type:=xlWorksheet) For i = 1 To Sheets.Count NewSheet.Cells(i, 1).Value = Sheets(i).Name Next i

4. On the File menu, click Close and Return to Microsoft Excel. 5. On the Control Toolbox, click Exit Design Mode to quit design mode and enable the
command button. 6. Click the command button on Sheet1. A new worksheet is created, listing the names of all the worksheets in the workbook.

Sub ListWorkSheetNames() Dim Sheetnames Sheetnames = Sheets.Count

Sheets.Add ActiveSheet.Name = SheetList Sheets(SheetList).Move after:=Sheets(Sheetnames + 1) For i = 1 To Sheetnames Range(A & i) = Sheets(i).Name Next i End Sub

You might also like