Closed Thread
Results 1 to 14 of 14

Capitalize first letter in each word, but NOT Proper

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,994

    Capitalize first letter in each word, but NOT Proper

    I want to capitalize the first letter of each word in my cell, but if I have something like FBI, or HHSC, I don't want the other letters to be Uncapitalized. I tried with Proper, and it uncapitalized my acronyms. Any ideas on a way around this?
    Last edited by jomili; 04-05-2012 at 04:31 PM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,660

    Re: Capitalize first letter in each word, but NOT Proper

    Something like this:

    =UPPER(LEFT(A1, 1))&MID(A1, 2, 100)

    Edit: Sorry, it won't work for multiple words in the cell as you write :/

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,994

    Re: Capitalize first letter in each word, but NOT Proper

    Almost, but not quite; here's what was in the cell:
    Please Login or Register  to view this content.
    Here's what the formula gave:
    Please Login or Register  to view this content.
    Here's the desired output:
    Please Login or Register  to view this content.
    I'd also like to have this in a macro that would 1)Convert all existing text and 2)convert everytime data is entered.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Capitalize first letter in each word, but NOT Proper

    I'll leave you to plumb this into the worksheet change event.

    Please Login or Register  to view this content.
    A RegExp solution would be prettier ...
    Last edited by shg; 04-05-2012 at 01:44 PM.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,994

    Re: Capitalize first letter in each word, but NOT Proper

    SHG, I can't comment on the "RegExp" solution, but my attempts at the "plumbing" are admittedly NOT very pretty. Here's my latest try, with the MostlyProper macro in Module1, and the code below in my target worksheet:
    Please Login or Register  to view this content.
    Whatever I do I keep coming up with the same error,"Compile Error: Argument not optional" on the MostlyProper code. I would appreciate a little more hand-holding if you would be so kind.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Capitalize first letter in each word, but NOT Proper

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Capitalize first letter in each word, but NOT Proper

    Try this in your worksheet code page

    Please Login or Register  to view this content.
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

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

    Re: Capitalize first letter in each word, but NOT Proper

    Hello jomili ,

    Here is the Regular Expression version. This code should be in a standard VBA module in your workbook.
    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!)

  9. #9
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,994

    Re: Capitalize first letter in each word, but NOT Proper

    My level of ignorance continues to astound me.

    SHG, even with your hand-holding on the worksheet change event I wasn't able to get it to work. No error, just no result. If I changed the name of MostlyProper I got an error, so I know we were accessing the module, it just didn't do anything.

    Leith, since I trust SHG's opinion when it comes to code, when he said a RegExp version would be prettier, I was excited to try your code. I pasted it into a standard module, then in the target worksheet I tried to do the event macro. But I ran into the original problem I had with SHG's code, namely that I couldn't figure out how to do the Worksheet Change Event routine. I tried what SHG supplied, substituting "FirstCap" for "MostlyProper", but that wouldn't work. Face it, I'm a lost cause.

    Kelshaer,
    Your code worked, right off the bat, the first time I tried it. No errors, no fuss, and it seems to be doing exactly what I want it to do. Unless Leith or SHG can point out the error of my ways regarding their macros, I'll run with yours.

    Thanks,
    John

  10. #10
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,994

    Re: Capitalize first letter in each word, but NOT Proper

    SHG, I just noticed you updated your code in your first post. I didn't see that before. With that code, your second (the worksheet change event) works, so ignore my last post.

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

    Re: Capitalize first letter in each word, but NOT Proper

    Hello jomili,

    Copy the macros below into your workbook. I have tested these on my computer and they work

    Worksheet Change Event Code
    Please Login or Register  to view this content.
    Standard Module - Capitalize First Letter Macro
    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,994

    Re: Capitalize first letter in each word, but NOT Proper

    And now I've verified that Leith's code works, SHG's code works, and Kelshaer's code works. I call that being triply blessed.

    For the most part the separate codes all produce the same results; "this is an FBI test" comes out as "This Is An FBI Test", but I've noticed this one difference:
    For SHG and Kelshaer, if I key in "this is a TeSt", the result is "This Is A Test".
    With Leith, the result is "This Is A TeSt".

    I can't say Leith is wrong, and I can't say SHG and Kelshaer are right. It's simply a different result. I can see situations where I'd like one or the other, so I'm glad there are differences.

    Thank you all for your help on this one.

    John

  13. #13
    Registered User
    Join Date
    01-24-2013
    Location
    Spain
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Capitalize first letter in each word, but NOT Proper

    I found that with Leith's code this case does not work: "test aBc" results in "Test aBc".
    Would it be possible to get "Test ABc"? Respect all caps in the text, even if they are not in the first position of the word.
    Also, with "this is a TeSt" or "thi sis a teSt" I get "This Is a TeSt" (it skips the "a").
    I am working with version 2007.
    I don't know exactly how Match works, I am reading the help and some examples now.
    Thanks!

  14. #14
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,660

    Re: Capitalize first letter in each word, but NOT Proper

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

Closed 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