Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Name of Added Worksheet

If I add a worksheet as in the code below, can I force the name of the new
sheet to something because this code was working fine on my PC, but on
another user's pc, the added sheet was Sheet4. Instead of changing their
template or whatever might be causing this, can I just force the new sheet to
some name, or can I otherwise determine the name of the new sheet and then go
to it. My next line of code is to rename this sheet1 anyway.

Sheets.Add Type:="Worksheet"
Sheets("Sheet1").Select

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Name of Added Worksheet

Mike,

Sheets.Add.Name = "Whatever You Want"

HTH,
Bernie
MS Excel MVP


"Mike H." wrote in message
...
If I add a worksheet as in the code below, can I force the name of the new
sheet to something because this code was working fine on my PC, but on
another user's pc, the added sheet was Sheet4. Instead of changing their
template or whatever might be causing this, can I just force the new sheet to
some name, or can I otherwise determine the name of the new sheet and then go
to it. My next line of code is to rename this sheet1 anyway.

Sheets.Add Type:="Worksheet"
Sheets("Sheet1").Select



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default Name of Added Worksheet

Hi Mike,

Change your code as

Sheets.Add Type:="Worksheet"
ActiveSheet.Name = "ABCD"

Where 'ABCD' is the name of your new worksheet

HTH,
--
Pranav Vaidya
VBA Developer
PN, MH-India
If you think my answer is useful, please rate this post as an ANSWER!!


"Mike H." wrote:

If I add a worksheet as in the code below, can I force the name of the new
sheet to something because this code was working fine on my PC, but on
another user's pc, the added sheet was Sheet4. Instead of changing their
template or whatever might be causing this, can I just force the new sheet to
some name, or can I otherwise determine the name of the new sheet and then go
to it. My next line of code is to rename this sheet1 anyway.

Sheets.Add Type:="Worksheet"
Sheets("Sheet1").Select

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Name of Added Worksheet

Try something like

ThisWorkbook.Worksheets.Add.Name = "MyNewName"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Mike H." wrote in message
...
If I add a worksheet as in the code below, can I force the name of the new
sheet to something because this code was working fine on my PC, but on
another user's pc, the added sheet was Sheet4. Instead of changing their
template or whatever might be causing this, can I just force the new sheet
to
some name, or can I otherwise determine the name of the new sheet and then
go
to it. My next line of code is to rename this sheet1 anyway.

Sheets.Add Type:="Worksheet"
Sheets("Sheet1").Select




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Name of Added Worksheet

Sub mike()
Sheets.Add
ActiveSheet.Name = "mike"
End Sub

--
Gary''s Student - gsnu200747


"Mike H." wrote:

If I add a worksheet as in the code below, can I force the name of the new
sheet to something because this code was working fine on my PC, but on
another user's pc, the added sheet was Sheet4. Instead of changing their
template or whatever might be causing this, can I just force the new sheet to
some name, or can I otherwise determine the name of the new sheet and then go
to it. My next line of code is to rename this sheet1 anyway.

Sheets.Add Type:="Worksheet"
Sheets("Sheet1").Select

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Name of Added Worksheet

I wasn't sure the newly added sheet would be the active sheet. Knowing that
makes this easy to do. Thanks to all who responded and so quickly.
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Name of Added Worksheet

Mike,

I wasn't sure the newly added sheet would be the active sheet. Knowing that ....


Be careful - that isn't always true - you can add sheets to workbooks that aren't currently active,
and so the activesheet will not be the just-added sheet. It is better coding practice to change the
name when you add the sheet or to set a worksheet object = to the new sheet, and set the name using
that object (see Dave Peterson's code.)

HTH,
Bernie
MS Excel MVP


"Mike H." wrote in message
...
makes this easy to do. Thanks to all who responded and so quickly.



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Name of Added Worksheet

Sheets.Add Type:="Worksheet"
ActiveSheet.Name = "whatyouwanthere"

(the newly added sheet is the activesheet)

You could also use:
Worksheets.Add.Name = "newsheetnamehere"

But I like this:

Dim NewWks as worksheet
set newwks = worksheets.add
newwks.name = "somename"

But then I can refer to the new worksheet by using the newwks variable. I can
do:

with newwks
.range("a1").value = "hi there"
.protect password:="pwd"
end with

And I don't have to rely on the name at all.

Mike H. wrote:

If I add a worksheet as in the code below, can I force the name of the new
sheet to something because this code was working fine on my PC, but on
another user's pc, the added sheet was Sheet4. Instead of changing their
template or whatever might be causing this, can I just force the new sheet to
some name, or can I otherwise determine the name of the new sheet and then go
to it. My next line of code is to rename this sheet1 anyway.

Sheets.Add Type:="Worksheet"
Sheets("Sheet1").Select


--

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
automatically appending newly added data on worksheet to a master list worksheet tabylee via OfficeKB.com Links and Linking in Excel 0 December 17th 09 04:24 PM
why is ...xls] being added to the name on my worksheet? beauwl Excel Worksheet Functions 2 October 3rd 07 05:00 PM
Detect New Worksheet being added sharonm Excel Programming 3 September 26th 07 07:12 PM
How to select an added worksheet davegb Excel Programming 6 June 23rd 06 10:55 PM
Stop Worksheet being added John Calder New Users to Excel 3 September 29th 05 03:07 PM


All times are GMT +1. The time now is 12:43 PM.

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

About Us

"It's about Microsoft Excel"