#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 70
Default Name Worksheet

I have a macro that creates a new worksheet when I run it. The given name
could be Sheet 1, Sheet 2, Sheet 3, etc. The point is that I never know what
number Sheet the macro will give the worksheet because it changes each time I
run it. I want to create a code that will find the worksheet with Sheet in
the name and change the name of the worksheet to Remaining. Here is what I
have so far.

newsht.Name = "Remaining"

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Name Worksheet

hi,

When you add a sheet it becomes the activesheet so use that

Worksheets.Add
ActiveSheet.Name = "Remaining"

Mike

"MCheru" wrote:

I have a macro that creates a new worksheet when I run it. The given name
could be Sheet 1, Sheet 2, Sheet 3, etc. The point is that I never know what
number Sheet the macro will give the worksheet because it changes each time I
run it. I want to create a code that will find the worksheet with Sheet in
the name and change the name of the worksheet to Remaining. Here is what I
have so far.

newsht.Name = "Remaining"

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 222
Default Name Worksheet

Just remember to find the sheet that's CURRENTLY named "remaining" and change
it's name first.

--
"Actually, I *am* a rocket scientist." -- JB

Your feedback is appreciated, click YES if this post helped you.


"Mike H" wrote:

hi,

When you add a sheet it becomes the activesheet so use that

Worksheets.Add
ActiveSheet.Name = "Remaining"

Mike

"MCheru" wrote:

I have a macro that creates a new worksheet when I run it. The given name
could be Sheet 1, Sheet 2, Sheet 3, etc. The point is that I never know what
number Sheet the macro will give the worksheet because it changes each time I
run it. I want to create a code that will find the worksheet with Sheet in
the name and change the name of the worksheet to Remaining. Here is what I
have so far.

newsht.Name = "Remaining"

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7,247
Default Name Worksheet

You can name the worksheet when you create it.

ThisWorkbook.Worksheets.Add().Name = "Remaining"

Or, since creating a sheet makes it the active sheet, you could use

ThisWorkbook.Worksheets.Add
ActiveSheet.Name = "Remaining"

If you really want to use a loop, try

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
If StrComp(Left(WS.Name, 5), "Sheet", vbTextCompare) = 0 Then
WS.Name = "Remaining"
Exit For
End If
Next WS





Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 27 Mar 2009 12:51:01 -0700, MCheru
wrote:

I have a macro that creates a new worksheet when I run it. The given name
could be Sheet 1, Sheet 2, Sheet 3, etc. The point is that I never know what
number Sheet the macro will give the worksheet because it changes each time I
run it. I want to create a code that will find the worksheet with Sheet in
the name and change the name of the worksheet to Remaining. Here is what I
have so far.

newsht.Name = "Remaining"

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 70
Default Name Worksheet

Terrific! Thank you for you're help!

"Mike H" wrote:

hi,

When you add a sheet it becomes the activesheet so use that

Worksheets.Add
ActiveSheet.Name = "Remaining"

Mike

"MCheru" wrote:

I have a macro that creates a new worksheet when I run it. The given name
could be Sheet 1, Sheet 2, Sheet 3, etc. The point is that I never know what
number Sheet the macro will give the worksheet because it changes each time I
run it. I want to create a code that will find the worksheet with Sheet in
the name and change the name of the worksheet to Remaining. Here is what I
have so far.

newsht.Name = "Remaining"



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 70
Default Name Worksheet

Okay, I'll keep that in mind.

"JBeaucaire" wrote:

Just remember to find the sheet that's CURRENTLY named "remaining" and change
it's name first.

--
"Actually, I *am* a rocket scientist." -- JB

Your feedback is appreciated, click YES if this post helped you.


"Mike H" wrote:

hi,

When you add a sheet it becomes the activesheet so use that

Worksheets.Add
ActiveSheet.Name = "Remaining"

Mike

"MCheru" wrote:

I have a macro that creates a new worksheet when I run it. The given name
could be Sheet 1, Sheet 2, Sheet 3, etc. The point is that I never know what
number Sheet the macro will give the worksheet because it changes each time I
run it. I want to create a code that will find the worksheet with Sheet in
the name and change the name of the worksheet to Remaining. Here is what I
have so far.

newsht.Name = "Remaining"

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 70
Default Name Worksheet

Absolutely charming. This is magnificent. Thank you!

"Chip Pearson" wrote:

You can name the worksheet when you create it.

ThisWorkbook.Worksheets.Add().Name = "Remaining"

Or, since creating a sheet makes it the active sheet, you could use

ThisWorkbook.Worksheets.Add
ActiveSheet.Name = "Remaining"

If you really want to use a loop, try

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
If StrComp(Left(WS.Name, 5), "Sheet", vbTextCompare) = 0 Then
WS.Name = "Remaining"
Exit For
End If
Next WS





Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 27 Mar 2009 12:51:01 -0700, MCheru
wrote:

I have a macro that creates a new worksheet when I run it. The given name
could be Sheet 1, Sheet 2, Sheet 3, etc. The point is that I never know what
number Sheet the macro will give the worksheet because it changes each time I
run it. I want to create a code that will find the worksheet with Sheet in
the name and change the name of the worksheet to Remaining. Here is what I
have so far.

newsht.Name = "Remaining"


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
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Charts and Charting in Excel 3 August 24th 06 07:26 PM
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Excel Discussion (Misc queries) 2 August 24th 06 05:26 PM
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Excel Worksheet Functions 2 August 24th 06 05:26 PM
Upload multiple text files into 1 excel worksheet + put the filename as the first column in the worksheet Aster Excel Worksheet Functions 3 March 12th 06 09:58 AM
I want in one worksheet to relatively link to/reference cells in another without changing the format of the current worksheet. [email protected] Excel Discussion (Misc queries) 0 September 22nd 05 04:39 PM


All times are GMT +1. The time now is 08:21 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"