View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default VBA to insert list of sheet names

Katherine,

Try

Private Sub CommandButton1_Click()
For i = 1 To Sheets.Count
Sheets("Sheet1").Range("A5")(i,1).Value = Sheets(i).Name
Next i
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Katherine Vale" wrote in message
...
I've got the following piece of code to create a list of
all the sheet names in a workbook. I want to modify this
so that the list of names created is automatically
inserted into Sheet1 (for example) starting at cell A5,
rather than creating a new sheet with the names on as is
happening at the moment.

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

Any suggestions greatly appreciated :)