Consulting

Results 1 to 11 of 11

Thread: Applying Proper Case to Strings

  1. #1
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location

    Applying Proper Case to Strings

    I have a worksheet within which users may enter words or phrases that include a variety of non-alpha characters. For example, boar/mix, boar-mix, Boar/mix or or any other delimiter and combination of words. I initially wrote a script which converted these entries (as they are entered) so that the sheet would reflect a standardized capitalization for each word in the name, i.e., Boar/Mix, Boar-Mix, etc.

    My script works fine when users apply either "/" or "-" as the delimiter; however, one user has used a character which I can't seem to get my script to force the proper case. See, for example, the following:

    Ok·cate·uce

    I can't seem to identify which character is being for the delimiter. So, I decided to cycle through the characters one at a time and capture the character based on a predefined list of allowed values (all of the lower case and upper case letters) and it works through every step of the process up to the point that of achieving "Ok Cate Uce" however when I apply the last command to replace the spaces with the delimiter character and apply the changes to the applicable cell, Excel automatically changes it back to Ok·cate·uce

    I can't figure out why that delimiter works differently from "/" and "-".

    Any ideas?

  2. #2
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Opv,

    I don't think it is a Proofing (Auto Correct) setting. Did you protect the worksheet?
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  3. #3
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by Leith Ross View Post
    Hello Opv,

    I don't think it is a Proofing (Auto Correct) setting. Did you protect the worksheet?
    Thanks. The worksheet is not protected. As I said, I can get a script to perform as desired with other delimiters (such as "/" or "-"). It's just that weird centered dot (whatever it is) that is throwing a kink into things.

  4. #4
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Opv,

    You should post your code and if possible a copy of the workbook.
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  5. #5
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by Leith Ross View Post
    Hello Opv,

    You should post your code and if possible a copy of the workbook.
    Well, I copied my code to a new workbook, with a clean worksheet and pasted in the phrase with the problematic delimiter, created a module, pasted in my code, and it works perfectly in the new workbook. Before I trouble the forum further, let me do some trouble shooting on my original workbook. Perhaps there is something in one of my other blocks of code that is causing the problem. Will advise. Thanks.

  6. #6
    VBAX Expert Leith Ross's Avatar
    Joined
    Oct 2012
    Location
    San Francisco, California
    Posts
    552
    Location
    Hello Opv,

    Hopefully it was just a corrupted workbook.
    Sincerely,
    Leith Ross

    "1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG"

  7. #7
    Sub M_snb()
       MsgBox "Ok cate Use"
       MsgBox StrConv("ok cate use", 3)
       MsgBox Replace(StrConv(Replace("ok/cate/use", "/", " "), 3), " ", "/")
       MsgBox Replace(StrConv(Replace("ok-cate-use", "-", " "), 3), " ", "-")
       MsgBox Replace(StrConv(Replace("ok_cate_use", "_", " "), 3), " ", "_")
       MsgBox Replace(StrConv(Replace("Ok·cate·uce", Chr(182), " "), 3), " ", Chr(182))
    End Sub

  8. #8
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    In Excel XP on WinXP:
    MsgBox Replace(StrConv(Replace("Ok·cate·uce", Chr(182), " "), 3), " ", Chr(182))
    'and
    Cells(1, 4) = Replace(StrConv(Replace("Ok·cate·uce", Chr(182), " "), 3), " ", Chr(182))
    Results = "Ok·cate·uce"
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    You should upgrade to:

       MsgBox Replace(StrConv(Replace("ok·cate·uce", Chr(183), " "), 3), " ", Chr(183))

  10. #10
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Thanks to everyone for the comments and suggestions. After realizing that my code worked when copied to a new workbook and clean worksheet, I went back and did some trouble shooting. The only thing I can figure is that something about my original workbook must have been corrupted. Regardless...problem solved. Thanks again!

  11. #11
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Yep, That did it
    MsgBox Replace(StrConv(Replace("ok·cate·uce", Chr(183), " "), 3), " ", Chr(183))
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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