Naming a newly inserted sheet using VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to insert a new sheet and name it "ABC":

Sheets.Add
Sheets("Sheet1").Name = "ABC"

This is fine for the first time as it inserts a new sheet called "Sheet1".
However the next time I do it the newly inserted sheet is called "Sheet2",
but the code is still looking for a "Sheet1".

Can I do something simple like:

Sheets.Add.Name = "ABC"

Thanks in advance.
 
Yes it does work the first time, but Excel automatically calls the second
sheet "Sheet2" in the workbook so it will debug as it will be looking for
"Sheet1". Actually I have just tried the following and it seemed to work...

Sheets.Add
Dim oSheet As Worksheet
Dim sName As String
sName = "ABC"
Set oSheet = Application.ActiveSheet
oSheet.Name = sName
 

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

Back
Top