+ Reply to Thread
Results 1 to 8 of 8

VBA Sentence case with exceptions

  1. #1
    Registered User
    Join Date
    12-14-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    VBA Sentence case with exceptions

    Hello,

    I am trying to perform sentence case on a cell with some exceptions.

    As an example lets say I have a cell that has the text "MARGARINE IS BETTER THAN BUTTER, TRUE OR FALSE".
    I would like to run some VBA to change this too "Margarine is better than butter, TRUE or FALSE".
    Currently I have this code:

    Please Login or Register  to view this content.
    This returns "Margarine is better than butter, true or false".

    I would like the true and false to stay in CAPS and also be able to add other exemptions as needed.

    Thanks in advance

    Tony

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA Sentence case with exceptions

    Please Login or Register  to view this content.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,970

    Re: VBA Sentence case with exceptions

    I have not tested Kenneth's solution, which may meet your needs perfectly. However, I developed a different approach from the ground up using words instead of letters but was unable to post earlier due to server issues.

    Add more words to the array at the bottom to add more exception words.

    Also, I recommend you use Option Explicit to guarantee that all variables are declared.


    I was unable to post my code here because the nanny service thinks it has a SQL injection attack, but here is the test file.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    12-14-2015
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    Re: VBA Sentence case with exceptions

    Kenneth that worked perfectly. Also allows me to exempt as Proper case if needed, brilliant.
    Thank you

  5. #5
    Forum Contributor
    Join Date
    09-05-2013
    Location
    Spring, Tx
    MS-Off Ver
    Excel 365
    Posts
    125

    Re: VBA Sentence case with exceptions

    Kenneth, I hope I am not breaking any rules here but I would like to know in your macro above say instead of TRUE & FALSE you were to use IN & OUT. How would you prevent it from being applies per say to words like DROPOUT or INPUT

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,970

    Re: VBA Sentence case with exceptions

    Quote Originally Posted by zhead View Post
    Kenneth, I hope I am not breaking any rules here
    Sorry to say that you are. Please start a new thread with your question, and feel free to copy Kenneth's code and post it there. You may also include a link back to this thread.

    Since you are not familiar with the rules please take two minutes to review our rules. There aren't many, and they are all important.

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

  7. #7
    Forum Contributor
    Join Date
    09-05-2013
    Location
    Spring, Tx
    MS-Off Ver
    Excel 365
    Posts
    125

    Re: VBA Sentence case with exceptions

    Thanks 6StrinJazzer. So can I reference this post or copy the code from here and paste it in a new post?

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,979

    Re: VBA Sentence case with exceptions

    @zhead

    Yes. Copy the code and post a link back to this thread. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Put A Space Between Sentence Case Words
    By zanshin777 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-04-2016, 04:21 PM
  2. [SOLVED] Sentence Case
    By zanshin777 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-04-2016, 02:35 PM
  3. [SOLVED] Sentence case
    By D_N_L in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-17-2014, 06:08 AM
  4. [SOLVED] Split Capital case and Sentence case from a cell
    By Latha Mani in forum Excel General
    Replies: 8
    Last Post: 03-26-2014, 03:29 AM
  5. Sentence case FORMULA??
    By simjambra in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-12-2009, 08:30 AM
  6. Change code HELP. Sentence Case
    By Corey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2006, 10:10 PM
  7. Replies: 2
    Last Post: 05-16-2006, 12:10 PM

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