Creating worksheets then name it

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?
 
T

Tim Zych

Dim wks As Worksheet
With ActiveWorkbook
Set wks = .Sheets.Add(After:=.Sheets("test"))
End With
wks.Name = "new sheet"
 
D

Dana DeLouis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top