Adding and Naming Worksheets

G

Guest

Guest
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.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try using its index number:
Sheets(1).Name = "new sheet"

I hope this helps.
Kind regards, Al.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,151
Members
449,068
Latest member
shiz11713

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top