Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Modifying Proper Capitalization.
by Allen Wyatt
(last updated August 29, 2018)
Like many people, Kirk copies information into Excel worksheets that originates in other places. The information that Kirk copies typically is all in CAPS, and he wants to convert it to what Excel refers to as "proper case" (only the first letter of each word is capitalized). The problem is, the PROPER worksheet function, which does the conversion, doesn't pay attention to the words it is capitalizing. Thus, words like a, an, in, and, the, and with are all initial-capped. Kirk doesn't want those words (and perhaps some others) capitalized.
There are several ways you can approach this problem. One is to use a rather long formula to do the conversion:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE( SUBSTITUTE(SUBSTITUTE(PROPER($B$13);" A ";" a "); " An ";" an ");" In ";" in ");" And ";" and "); " The ";" the ");" With ";" with ")
Remember, this is all a single formula. It does the case conversion, but then substitutes the desired lowercase words (a, an, in, and, the, with). While this is relatively easy, the utility of the formula becomes limited as you increase the number of words for which substitutions should be done.
Perhaps a better approach is to use a user-defined function macro to do the case conversion for you. The following function checks for some common words that should not have initial caps, making sure they are lowercase.
Function MyProper(str As String) Dim vExclude Dim i As Integer vExclude = Array("a", "an", "in", "and", _ "the", "with", "is", "at") Application.Volatile str = StrConv(str, vbProperCase) For i = LBound(vExclude) To UBound(vExclude) str = Application.WorksheetFunction. _ Substitute(str, " " & _ StrConv(vExclude(i), vbProperCase) _ & " ", " " & vExclude(i) & " ") Next MyProper = str End Function
Words can be added to the array, and the code automatically senses the additions and checks for those added words. Notice, as well, that the code adds a space before and after each word in the array as it does its checking. This is so that you don't have the code making changes to partial words (such as "and" being within "stand") or to words at the beginning of a sentence. You can use the function within a worksheet in this way:
This usage returns the modified text without adjusting the original text in B7.
If you prefer, you can use a function that takes its list of words from a named range in the workbook. The following function uses a range of cells named MyList, with a single word per cell. It presumes that this list is in a worksheet named WordList.
Function ProperSpecial(cX As Range) ' rng = target Cell Dim c As Range Dim sTemp As String sTemp = Application.WorksheetFunction.Proper(cX.Value) For Each c In Worksheets("WordList").Range("MyList") sTemp = Application.WorksheetFunction.Substitute( _ sTemp, Application.WorksheetFunction.Proper( _ " " & c.Value & " "), (" " & c.Value & " ")) Next c ProperSpecial = sTemp End Function
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11267) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Modifying Proper Capitalization.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
One of the financial worksheet functions provided in Excel is the XIRR function. This is used to figure out an internal ...Discover More
The SUMIFS function can be quite powerful in conditionally summing information based on criteria you specify. This tip ...Discover More
Want to chop off everything after a certain point in a number? The TRUNC function can help with this need.Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.