Naming a worksheet

  • Thread starter Thread starter Tangier
  • Start date Start date
T

Tangier

How do you name a worksheet when you are outputting a new worksheet as
a result of running a macro.

Currently the sheets are being named "Sheet1", "Sheet2", etc.

Thanks
 
"outputting a new worksheet"? Do you mean you are inserting a new worksheet
into the workbook and you want to name that newly inserted worksheet? If
so...

Adding New Sheet At End Of Existing Sheets
===========================================
Worksheets.Add After:=Worksheets(Worksheets.Count)
Worksheets(Worksheets.Count).Name = "New Sheet Name"

Adding New Sheet Somewhere Else
=================================
Worksheets.Add After:=Worksheets("Sheet1")
For X = 1 To Worksheets.Count
If Worksheets(X).Name = "Sheet1" Then
Worksheets(X + 1).Name = "Just Added"
Exit For
End If
Next
 
One more:

Dim NewWks as worksheet
....
set newwks = worksheets.add
on error resume next
newwks.name = "Whateveryouwanthere"
if err.number <> 0 then
err.clear
msgbox "Rename failed
end if
 
Back
Top