bobhc
Excel Ninja
Good day all
I have two pieces of code to create a list of tab names in a new work sheet, the code is linked to an active x button on an empty sheet but it creates the list in a fresh sheet I was hoping to keep the list and button on the same sheet.
The first piece of code creates the list but if there is a = in the beginning of the tab name the code will hang at that tab.
The second piece of code takes care of the problem = in tab names......but I do not have the faintest idea what the @ does or how the code works.
Could someone a) explain the code and b) point out if there is a way to keep the button on the same sheet as the tab list.
[pre]
[/pre]
I have two pieces of code to create a list of tab names in a new work sheet, the code is linked to an active x button on an empty sheet but it creates the list in a fresh sheet I was hoping to keep the list and button on the same sheet.
The first piece of code creates the list but if there is a = in the beginning of the tab name the code will hang at that tab.
The second piece of code takes care of the problem = in tab names......but I do not have the faintest idea what the @ does or how the code works.
Could someone a) explain the code and b) point out if there is a way to keep the button on the same sheet as the tab list.
[pre]
Code:
Code for tabs without the = sign
Set NewSheet = Sheets.Add(Type:=xlWorksheet)
For i = 1 To Sheets.Count
NewSheet.Cells(i, 1).Value = Sheets(i).Name
Next i
Code for tabs with the = sign
Private Sub CommandButton1_Click()
Set NewSheet = Sheets.Add(Type:=xlWorksheet)
For i = 1 To Sheets.Count
With NewSheet.Cells(i, 1)
.NumberFormat = "@" 'text
.Value = CStr(Sheets(i).Name)
End With
Next i
End Sub