+ Reply to Thread
Results 1 to 14 of 14

Check for Valid Sheet Name

  1. #1
    Registered User
    Join Date
    05-19-2008
    Posts
    16

    Check for Valid Sheet Name

    So I have a macro that creates a new sheet and names it based off a cell value (date, MM-DD-YY), and copies a 'Template' sheet to it, values only. Every so often, two sheets need to be made with the same date. Could someone help me in the right direction in creating an addition to the below code that will add an A, B, or C at the end of the sheet name if the name is already taken?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,558
    try
    Please Login or Register  to view this content.
    Last edited by jindon; 05-20-2008 at 11:17 PM.

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527
    Ah jindon has beaten me to the punch, but here's my suggested solution nonetheless:

    Please Login or Register  to view this content.
    HTH

    Robert

  4. #4
    Registered User
    Join Date
    05-19-2008
    Posts
    16

    Having additional problems

    Thank you Jindon and Trebor for your replies. Jindon, your addition worked perfectly. However, Trebor I like the addition of the A, B, C on the date.

    I am having some problems with the code though. The code right now is going through ReNameA, ReNameB, and stopping at ReNameC. When a second tab is created with the same date, it will go to C and error. I would like it to only add an A if the sheet name is already taken, B if the Date+A is taken, and C if the Date+B is taken.

    Any suggestions? I appreciate you spending your time with this.

    Please Login or Register  to view this content.
    Last edited by degmania; 05-21-2008 at 03:07 AM.

  5. #5
    Registered User
    Join Date
    05-19-2008
    Posts
    16
    Any help on the previously posted question will be appreciated!

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,558
    try
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527
    Hi degmania,

    Sorry it has taken me awhile to respond but it proved far tricker than I thought.

    Have a look at the following which pops up an InputBox for the user to fill in if the proposed tab name already exists within the workbook. This way it will keep looping through until a unique name is found - i.e. not just limited to appending A, B or C to the existing proposed name.

    Let me know how it goes and/or your thoughts.

    Kind regards,

    Robert

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-19-2008
    Posts
    16

    Error

    Jindon,

    I have been trying out your code and received an error. Creating sheets with unique dates works fine. If I create a sheet with a date already in use, X is set to 8 and the macro will loop - continuously changing the letter, and freezing excel. This is beyond my knowledge, how can we make it so the trigger to exit the loop, x, is something other then 0 or >0? Novice example; X = unique sheet name Then Exit Do

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,558
    OK
    Can you change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-19-2008
    Posts
    16

    Robert

    Thank you for the effort! I am able to create sheets with unique names. When creating a sheet with a taken name, I receive the following error, on the line .Name = Newname;

    'Run-time error '1004':Cannot rename a sheet to the same name as another sheet, a referenced object library or a workbook referenced by Visual Basic. '

    For your reference I am using Excel 2007 and a file in compatibility mode.

    I am learning a lot just working with your code, thanks.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,558
    If you are talking about my code, that line should be
    Please Login or Register  to view this content.
    As in my last code.

  12. #12
    Registered User
    Join Date
    05-19-2008
    Posts
    16

    Jindon

    Jindon, the change corrected the error, many thanks! I will need to study this now so I can walk away from this a little more intelligent. I will comment the code with your name and this websites address.

    Robert, as I am aiming for ease of use and minimal user action I am going to use Jindon's code. I appreciate all your effort on my behalf.

    You have both shown great generosity!

  13. #13
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527
    Hi degmania,

    That's strange - I originally tested it in Excel 2003 but have now just run it in Excel 2007 and it worked prefectly

    Regards,

    Robert

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,558
    degmania,
    CORRECTION!
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    Whole code
    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