+ Reply to Thread
Results 1 to 4 of 4

Macro to convert predefined text only to lower case

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2012
    Location
    Egypt
    MS-Off Ver
    Excel 2003
    Posts
    40

    Macro to convert predefined text only to lower case

    Hi valued members,

    I need a macro that enables me to select a range of cells by mouse, check their content for predefined text (mostly prepositions like "to, in, with, at, of..etc) and convert that certain text only into lower case, while leaving other textual content as is.

    I appreciate your help.
    Thanks in advance.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to convert predefined text only to lower case

    Like so... I could make it shorter, but this is the easiest to understand. Notice most of these short words include spaces before and after?
    Option Compare Text
    
    Sub ReplaceSpecial()
    Dim cell As Range, MyStr As String
    
    Application.ScreenUpdating = False
    For Each cell In Selection
        MyStr = cell.Value
        MyStr = Replace(MyStr, " to ", " to ")
        MyStr = Replace(MyStr, "the ", " the ")
        MyStr = Replace(MyStr, " in ", " in ")
        MyStr = Replace(MyStr, " with ", " with ")
        MyStr = Replace(MyStr, " at ", " at ")
        MyStr = Replace(MyStr, " of ", " of ")
        MyStr = Replace(MyStr, " and ", " and ")
        MyStr = Replace(MyStr, " for ", " for ")
        cell.Value = MyStr
    Next cell
    Application.ScreenUpdating = True
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-19-2012
    Location
    Egypt
    MS-Off Ver
    Excel 2003
    Posts
    40

    Re: Macro to convert predefined text only to lower case

    Works perfectly
    Thanks a lot JBeaucaire

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to convert predefined text only to lower case

    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above and mark this thread as SOLVED. Thanks.

+ 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