![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
I have a VBA routine where I need to add and rename worksheets. I have a list of names and some date for each name, and new names and data are added each week. When a new name is encountered, the code creates a new worksheet for that person. The new worksheets are automatically named "Sheet 1", "Sheet 2", "Sheet 3" etc.
The problem occurs when I try to rename the new worksheets. My code works fine for the first one but times out on the second and subsequent ones (I never know how many there are going to be). What I need is a way to change the name of the new worksheet when I don't know its current name. |
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
Try using its index number:
Sheets(1).Name = "new sheet" I hope this helps. Kind regards, Al. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
Would the following work OK for you?
With Worksheets.Add .Move after:=Worksheets(Worksheets.Count) .Name = YourName End With [ This Message was edited by: Mudface on 2002-03-14 12:47 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|