+ Reply to Thread
Results 1 to 5 of 5

VBA to Name Wkst - Help with Removing special char. & invalid names

  1. #1
    Registered User
    Join Date
    04-11-2012
    Location
    milwaukee, wi
    MS-Off Ver
    Excel 2007
    Posts
    11

    VBA to Name Wkst - Help with Removing special char. & invalid names

    Hi - I'm a VBA newbie, but am making a little progress. i have a macro (thanks to the help of this forum) to rename a wkst based on a cells value. It works great. But some of the cells have invalid wkst names, producing an error.

    I want it to fix invalid wkst names (remove special characters & shorten if too long, etc). I found a script to remove special characters, but don't know how to incorporate into my existing code or how to shorten the name if its too long.

    Existing Code:
    Please Login or Register  to view this content.
    Code i want to incorporate to remove special characters (have not tested it)
    Please Login or Register  to view this content.
    And then how would i get it to shorten to less than 32 characters?
    Millions of thanks!
    Last edited by popps; 04-17-2012 at 11:50 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA to Name Wkst - Help with Removing special char. & invalid names

    Example

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-11-2012
    Location
    milwaukee, wi
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA to Name Wkst - Help with Removing special char. & invalid names

    Hmmm, i tried it but it gave me an error when trying to rename it "1161 Stables Commercial Properties, LLC"

    I tried adding a comma to the .Pattern line, but it didnt work
    Please Login or Register  to view this content.
    Any ideas?

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA to Name Wkst - Help with Removing special char. & invalid names

    Are you trying to rename after adding new sheet by hand?

    If so,

    1) The code is not running for that action.
    2) Error because sheet name is too long.

    Else
    P2 of newly created sheet is always EMPTY.
    So you will need to change Sh.Range("P2") to other sheet reference.

    And the length should be less than 31, so
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    Last edited by jindon; 04-17-2012 at 12:18 PM.

  5. #5
    Registered User
    Join Date
    04-11-2012
    Location
    milwaukee, wi
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA to Name Wkst - Help with Removing special char. & invalid names

    You are right, the name was too long - i thought the char limit was 32 but it is 31. i changed it the code to 30 and it worked. Thanks so much jindon!!!!!!

    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