+ Reply to Thread
Results 1 to 5 of 5

Rename Sheet Tab Code Doesn't Handle Duplicates

  1. #1
    Registered User
    Join Date
    09-26-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    20

    Rename Sheet Tab Code Doesn't Handle Duplicates

    Hi.

    I have the following code I got from this forum. It renames a sheet based on the contents of cell B5. It works fine but when there is a duplicate name in B5 (I have multiple sheets) it errors.
    Is there something I can add that will handle duplicate names, e.g. add (1) after the name if it is a duplicate?

    Thanks

    Ian

    Please Login or Register  to view this content.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,363

    Re: Rename Sheet Tab Code Doesn't Handle Duplicates

    Hi irose_57 and welcome to the formu,

    I searched on Excel VBA Worksheet Exists and came up with this site.
    http://www.ozgrid.com/VBA/IsWorkbookOpen.htm#WORKSHEET

    I believe this is what you want.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    09-26-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    20

    Re: Rename Sheet Tab Code Doesn't Handle Duplicates

    Thanks for the quick reply!

    Had a look there and couldn't see what I wanted (more likely didn't understand it!)

    The code I have works fine but it stops when it hits a duplicate. My workbook has mutiple sheets and each sheet has a persons surname in B5. When it is renaming the sheets it stops if there is someone with the same surname in B5 as you can't have two sheets with the same name.

    What I'd like the code to do is add a unique identifier to the surname if it is a duplicate e.g Sheet1=Bloggs, Sheet2 =Bloggs1

    Thanks

    Ian

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rename Sheet Tab Code Doesn't Handle Duplicates

    Hello irose_57,

    You can trap the error that occurs when a sheet is named the same as another sheet in the workbook. Here is your macro modified to do so.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    09-26-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    20

    Re: Rename Sheet Tab Code Doesn't Handle Duplicates

    Thanks Leith.

    Tried that and it renamed the sheets 1 through x without using the contents of B5 on each sheet.

    I've tried the following code that I found on another post (I've changed it slightly) and it's working.

    Thanks for everyones help.

    Ian

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1