Worksheets

Sunday, November 28, 2010

VB code to list names of all worksheets present in a workbook

Sub ListSheetNames()
Dim Wsheet As Worksheet
Dim Rownumber As Integer
Rownumber = 1
'Intialize the row in which the name listing would start'
Sheets("INDEX").Range("A:A").Clear
'Clear any data previously present in column A'
For Each Wsheet In Worksheets
Sheets("INDEX").Cells(Rownumber, 1) = Wsheet.Name 

'List all the names of sheets present in the workbook in Column A (1)' 
Rownumber = Rownumber + 1
'Increment the row value for continuous listing'
Next Wsheet
End Sub


Copy this code into a new module in the Visual Basic Editor(Alt+F11).
You could further create a drop down list of sheet names by using this data. For how to create a drop down list please see  
How to create a drop down list using data validation?

 

No comments:

Post a Comment