Consulting

Results 1 to 6 of 6

Thread: Solved: WS Name function

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location

    Solved: WS Name function

    I have a routine that will create multiple worksheets within a workbook and name these worksheets based upon certain data.

    However if an invalid character is in the data, my code will crash.

    Does anyone have a function which will strip a variable of unusable characters for naming a worksheet?

    Example:
    "This/Name" is invalid. I'd like to turn this into "This-Name".

    Thanks

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    How are the invalid characters picked up? you can always use the worksheet function SUBSTITUTE like this:
    [VBA]Application.WorksheetFunction.Substitute(Range("A1").Value, "/", "-") [/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location
    Thanks for the reply. I'm looking for a function that replaces any unusable character. For instance, you can't use ? > @ : (I'm guessing at these).

    Does anyone have a function that identifies ALL non-usable characters for naming a worksheet?

    THanks again.

  4. #4
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    Here are the characters that Excel does not allow in worksheet names: * [ ] \ : / ?
    If you did as Simon suggested, and used 7 Substitute functions, you would have your filter.

  5. #5
    That's quite astonishing. Curiously enough, fb7894, the only illegal character in your example list is the colon (. I was amazed that just about any character you want to use is legal for a sheet name. nst1107 furnished the list of unusables which I was unable to find execept by trying each one.

  6. #6
    VBAX Regular
    Joined
    Jun 2008
    Posts
    72
    Location
    Quote Originally Posted by Cyberdude
    I was amazed that just about any character you want to use is legal for a sheet name.
    Me too. I guess I just assumed the list of illegal characters would be lengthy. That's what I get for assuming. THanks for the help everyone!

Posting Permissions

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