Creating worksheets then name it

  • Thread starter Thread starter john
  • Start date Start date
J

john

I am attempting to create a new worksheet in a macro and
give it a specified name. I can create the worksheet with
the following command:

ActiveWorkbook.Sheets.Add After:=Worksheets("test")

What I can't figure out is how to name the newly created
worksheet.

Anyone have an idea on how to do this?
 
Dim wks As Worksheet
With ActiveWorkbook
Set wks = .Sheets.Add(After:=.Sheets("test"))
End With
wks.Name = "new sheet"
 
I don't think the following is shown in the documentation, but I think it
works ok...

Sub Demo()
Worksheets.Add(Before:=Sheets(1)).Name = "Test" & Sheets.Count
End Sub
 
Back
Top