Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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: Making PROPER Skip Certain Words.
by Allen Wyatt
(last updated July 12, 2014)
Terry uses the PROPER worksheet function all the time to change the case of text in his worksheets. He wonders if there is a way to instruct the function to ignore certain words, so that they aren't started with a capital letter. It is not unusual for him to have to go back after using PROPER and change words like "the" or "an" to all lowercase. If PROPER could skip changing such words automatically, it would be a big help.
One way to approach this is to use the SUBSTITUTE worksheet function in conjunction with the PROPER function. For instance, if you wanted to find instances of the word "The" with "the", you could use the following:
=SUBSTITUTE(PROPER(A1)," The "," the ")
Note the inclusion of the space before and after what you are searching for and what you are replacing. This insures that only full words are modified. It also makes sure that no changes are made at the beginning of the cell value or at the end.
If you wanted to search for other words that needed replacing, you can simply increase the number of instances of SUBSTITUTE in the formula:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(PROPER(A1)," The ", " the ")," An "," an ")," And "," and ")
This can obviously get a bit awkward if you have a lot of words you want to exclude from being modified. In that case you'll need to resort to using a macro. The following macro, written as a user-defined function, can be used to convert all words in a cell to initial caps (just like PROPER), but make sure that certain defined words are lowercase.
Function Title(ByVal ref As Range) As String Dim vaArray As Variant Dim c As String Dim i As Integer Dim J As Integer Dim vaLCase As Variant Dim str As String ' Array contains terms that should be lower case vaLCase = Array("a", "an", "and", "in", "is", _ "of", "or", "the", "to", "with") c = StrConv(ref, 3) 'split the words into an array vaArray = Split(c, " ") For i = (LBound(vaArray)+1) To UBound(vaArray) For J = LBound(vaLCase) To UBound(vaLCase) ' compare each word in the cell against the ' list of words to remain lowercase. If the ' Upper versions match then replace the ' cell word with the lowercase version. If UCase(vaArray(i)) = UCase(vaLCase(J)) Then vaArray(i) = vaLCase(J) End If Next J Next i ' rebuild the sentence str = "" For i = LBound(vaArray) To UBound(vaArray) str = str & " " & vaArray(i) Next i Title = Trim(str) End Function
To use the macro, all you need to do is use the following in your worksheet:
You can also find an additional approach on accomplishing the desired conversion at this site:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10560) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Making PROPER Skip Certain Words.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Need to find a median value in a series of values? It's easy with the MEDIAN function. What isn't as easy is to derive the ...Discover More
Need to know what day of the year a certain date is? You can figure it out easily using the formulas in this tip.Discover More
Got a ton of names from which you need to select a few random names? There are several ways you can extract what you 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.