Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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.
Written by Allen Wyatt (last updated January 18, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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:
=Title(A1)
You can also find an additional approach on accomplishing the desired conversion at this site:
http://dmcritchie.mvps.org/excel/proper.htm
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10560) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Making PROPER Skip Certain Words.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
You can use the IF worksheet function to test for a number of different conditions or values. You can't use it to check ...
Discover MoreThe SUMIFS function allows you to specify criteria by which values can be included in a sum. Putting together the ...
Discover MoreWhen working with data taken from the real world, you often have to determine which certain conditions were met, such as ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-05-21 13:28:55
Willy Vanhaelen
To use this tip's UDF you have to enter the text of a title in a cell (A1 in the example) and then enter =Title(A1) in another cell that then display's the title with the adjusted case.
I think it would be easier to simply type the text of your title (all in lower case i.e.) in the cell where you want it and then simply run a macro that adjusts the case of all the words.
The following macro based on the one I posted May 3rd will do just that:
Sub AdjustTitleCase()
Dim vaArr As Variant, i As Integer
Const sList = " A An And In Is Of Or The To With "
vaArr = Split(StrConv(Selection(1), 3), " ")
For i = (LBound(vaArr) + 1) To UBound(vaArr)
If InStr(sList, " " & vaArr(i) & " ") Then vaArr(i) = LCase(vaArr(i))
Next i
Selection(1) = Join(vaArr)
End Sub
2023-05-03 12:02:30
Willy Vanhaelen
I managed to make a version of the Title UDF (user defined function) that uses only one loop instead of three:
Function Title(ref) As String
Dim vaArr As Variant, i As Integer
Const sList = " A An And In Is Of Or The To With " 'words to make lowercase
vaArr = Split(StrConv(ref, 3), " ") 'split the words into an array
For i = (LBound(vaArr)+1) To UBound(vaArr) 'make word lowercase if in sList
If InStr(sList, " " & vaArr(i) & " ") Then vaArr(i) = LCase(vaArr(i))
Next i
Title = Join(vaArr)
End Function
You use this function by pointing to the cell containing the title, for example : =Title(A1).
You can also type the title directly as a variable, for example: =Title("THIS IS A TRIAL"): the result will be "This is a Trial".
2023-05-02 09:28:38
J. Woolley
For more on this subject, see https://excelribbon.tips.net/T011267_Modifying_Proper_Capitalization.html
2020-02-15 19:31:30
Peter J Moran
Hi Allen,
May I suggest, that while the Function you provided is great, as you would know Macros are much more versatile to use wherever they are needed, which I noted was one of the first things Dave McRitchie mentions in the article you referred to.
Many thanks for all your tips.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments