Name Worksheet

M

MCheru

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"
 
M

Mike H

hi,

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

Worksheets.Add
ActiveSheet.Name = "Remaining"

Mike
 
J

JBeaucaire

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

Chip Pearson

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)
 
M

MCheru

Terrific! Thank you for you're help!

Mike H said:
hi,

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

Worksheets.Add
ActiveSheet.Name = "Remaining"

Mike
 

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