Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Ant
 
Posts: n/a
Default Naming a newly inserted sheet using VBA

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.
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

What happened when you tried it?

(It worked for me.)

Ant wrote:

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.


--

Dave Peterson
  #3   Report Post  
Ant
 
Posts: n/a
Default

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

"Dave Peterson" wrote:

What happened when you tried it?

(It worked for me.)

Ant wrote:

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.


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get other sheet names into a column Keyser Excel Worksheet Functions 2 August 27th 05 02:02 AM
Using a relative SHEET reference for source data in a chart James Charts and Charting in Excel 6 August 16th 05 05:07 PM
Copying Specific Values From Sheet Jenn Excel Discussion (Misc queries) 1 July 11th 05 09:22 PM
in VBA Sheets("mysheet").Copy Befo=Sheets(1) how do i get a reference to the newly created copy of this sheet? Daniel Excel Worksheet Functions 1 July 6th 05 09:57 PM
Subset of one sheet on another sheet bxb7668 Excel Worksheet Functions 3 April 25th 05 03:55 PM


All times are GMT +1. The time now is 07:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"