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.

Making PROPER Skip Certain Words

by Allen Wyatt
(last updated July 12, 2014)

2

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

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Roman Numerals for Page Numbers

Yes, Excel can work with Roman numerals, and it even provides a worksheet function that converts to them. How you use those ...

Discover More

Replacing in Worksheets and Comments At the Same Time

If you need to replace information that may appear in cells, comments, and text boxes, your best bet is to use a macro. This ...

Discover More

Undesired Font in Form Fields

If you get unwanted formatting in your form fields, it could be because of the way you are formatting the line on which the ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

MORE EXCELTIPS (RIBBON)

Using COUNTIF with Colors

Excel allows you to easily format cells with different fonts, borders, and colors. If you want to count the number of cells ...

Discover More

Making VLOOKUP Trigger a Macro

VLOOKUP is an oft-used worksheet function to lookup values in a data table. If the function cannot return a value, it ...

Discover More

Cleaning Text

You can use the CLEAN worksheet function to remove any non-printable characters from a cell. This can come in handy when you ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 8?

2015-06-04 08:33:57

John K

I'm interested in this, however I can't use macros in my case. Is it possible to use an array formula for this.. i.e. create a table of exclusions, and use that to exclude the specific words?


2015-01-06 18:43:56

Peter Atherton

Here is my version of Title case.

Function Title(ByVal ref As Range, Optional bFormal As Boolean = True) As String
'Thanks to Jim Cone who pointed out that the original function _
did not deal with hyphens & upper case words such as 'IBM' or indeed Mcs and Macs.
'Completed 5 Jan 2015
'
Dim vaArray As Variant
Dim LLo As Long, LMid As Long, LHi As Long
Dim c As String, sTemp As Variant
Dim i As Integer, iWrdCap As Variant
Dim iPos As Integer, iMc As Integer, _
iMac As Integer, iHyphen As Integer
Dim vaLCase As Variant
Dim Str As String, sChr As String

'Is there a capitalised word in the reference? e.g. IBM or BAE _
if so find out its position for later
sTemp = Split(ref, " ")
iWrdCap = ""
For i = LBound(sTemp) To UBound(sTemp)
If sTemp(i) = StrConv(sTemp(i), vbUpperCase) Then
iWrdCap = i
Exit For
End If
Next i

' Array contains terms that should be lower case
vaLCase = Array("A", "Am", "An", "And", "Be", "Der", "Do", "Du", "In", "Is", _
"Me", "My", "Of", "On", "Or", "She", "Than", "The", "To", "Van", "Von", "We", "with")

If bFormal Then
c = WorksheetFunction.Proper(ref)
Else
c = StrConv(ref, vbProperCase)
End If
'=======================================
'Special Cases
iMac = InStr(1, c, "Mac")
If iMac > 0 Then
Mid(c, iMac + 3, 1) = UCase(Mid(c, iMac + 3, 1))
End If

iMc = InStr(1, c, "Mc")
If iMc > 0 Then
Mid(c, iMc + 2, 1) = UCase(Mid(c, iMc + 2, 1))
End If

iPos = InStr(1, c, "-On-")
If iPos > 0 Then
c = Replace(c, "-On-", "-on-")
End If

iHyphen = InStr(1, c, " - ")
If iHyphen > 0 Then
c = Replace(c, " - ", "-")
End If
'=======================================
'split the words into an array
vaArray = Split(c, " ")

'i ignores the first value - that should be Proper case
For i = 1 To UBound(vaArray)
LLo = LBound(vaLCase)
LHi = UBound(vaLCase)
If Right(vaArray(i), 1) Like "[',.]" Then
sChr = Left(vaArray(i), Len(vaArray(i)) - 1)
Else
sChr = vaArray(i)
End If

'Binary Search for sChr
Do Until LLo > LHi
'Find the midpoint of the array
LMid = (LLo + LHi) 2
If sChr = vaLCase(LMid) Then
'sChr is found so return the location & quit loop
vaArray(i) = LCase(sChr)
Exit Do

ElseIf sChr < vaLCase(LMid) Then
'sFind is higher than mid-point so _
throw away the top half
LHi = LMid - 1
Else
'sFind is lower than than mid-point so _
discard the bottom half
LLo = LMid + 1
End If

Loop


Next i

' rebuild the sentence
Str = ""
For i = LBound(vaArray) To UBound(vaArray)
If i = iWrdCap Then
Str = Str & " " & UCase(vaArray(i))
Else:
Str = Str & " " & vaArray(i)
End If
Next i


Title = Trim(Str)
End Function

Enter the formula as =Title(a1) to use the application.Proper function as the working basis. or =Title(a1,False) to use visual basic's strConv function.

StrConv will return I'd as I'd where the Proper function returns I'D.

In most cases False is not required.


Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing
Share