Adding and Naming Worksheets
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Adding and Naming Worksheets

  1. #1
    Guest

    Default

     
    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. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try using its index number:
    Sheets(1).Name = "new sheet"

    I hope this helps.
    Kind regards, Al.


  3. #3
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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 ]

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com