Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Replacing the Last Comma.
Written by Allen Wyatt (last updated March 11, 2026)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365
Rebecca is looking for a way to replace the last comma in a sentence with the word "and." She apparently needs to perform this type of edit quite a bit, and thought there might be a quick and easy way to doing the edit rather than needing to manually do it.
There is no built-in way to do this specific edit in Word, but you can create a simple macro that will search for the last comma, delete it, and then type the desired word. The following is an example of such a macro.
Sub ReplaceLastComma()
Dim rSentence As Range
Dim rComma As Range
Dim rCheck As Range
Dim re As Object
Dim J As Long
Dim sRaw As String
Dim sAfter As String
' Set to True if you want the last comma to remain
' Set to False if you want the last comma deleted
Const bOxford As Boolean = True
Set re = CreateObject("VBScript.RegExp")
re.Pattern = "^\s*and\b"
re.IgnoreCase = True
re.Global = False
For Each rSentence In Selection.Sentences
sRaw = rSentence.Text
For J = Len(sRaw) To 1 Step -1
If Mid(sRaw, J, 1) = "," Then
Set rComma = rSentence.Duplicate
rComma.Start = rSentence.Start + J - 1
rComma.End = rComma.Start + 1
Set rCheck = rSentence.Duplicate
rCheck.Start = rComma.End
rCheck.End = rSentence.End
sAfter = rCheck.Text
If re.Test(sAfter) Then
If Not bOxford Then rComma.Delete
Else
If bOxford Then
rComma.Text = ", and"
Else
rComma.Text = " and"
End If
End If
Exit For
End If
Next J
Next rSentence
End Sub
The macro steps through each sentence in whatever text you've selected in the document. The macro steps backwards through the text of each sentence. (The text is assigned to the variable sRaw for ease of processing.) If a comma is found, then the text is checked to see if it is followed by the word "and" already. If so, then the comma is deleted based on the setting of the bOxford constant. (The purpose of the constant is to specify if you want to include an Oxford comma or not.) The word "and" is also added, if it doesn't already exist.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12378) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Replacing the Last Comma.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!
You get a document from a colleague and you notice that each paragraph starts with a tab character. Here are a couple of ...
Discover MoreSeeing where every space is within a document can be very helpful in polishing your editing. Here's how to make those ...
Discover MoreWord allows you to place text in multiple text boxes and have that text flow from one text box to another. This tip ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-01-31 10:29:08
Tomek
Oxford comma is fine in English, but in some other languages you ***never*** put comma before "and", or rather before its equivalent.
Nevertheless, the macro can be easily modified to Oxford comma.
2023-01-30 04:53:40
Zvi
Can this macro be modified to go through ALL sentences in a document?
Also if a sentence already has "and" instead of the last comma, won't it replace the last comma it finds with an "and", so there will be two "ands" at the end of the sentence?
2021-10-19 21:38:20
Roy
But... but... I thought Regular Expressions could do anything... there must be a way... the concept can't fail, even a little bit... people gush over it too much for that to be possible...
So, what's the RegEx way?
Ah, our old friend, the Oxford comma. like them when items are distinct and so need distinction. I can do without them without raging when meaning is utterly clear (that's the bar: since it IS utterly clear with them, it must also be so without them). But when lazy people use a smidge of knowledge (knowing some kind of something exists concerning them) to gloss away their laziness and ignorance... no.
I still remember my first grade teacher, Miss Henry, telling us you don't HAVE to use that last comma, that about 50% ("%" being a learning experience itself) of the time writers don't use the last one. Standing near the door to the hall (we had another in the opposite corner to the outside, to the old playground no one really used due to bees in the telephone pole holding a basketball hoop (no, er, Shinola, a telephone pole at each end of the "court") but we had it and went past those bees everyday for recess), a bit bulky she was so "near" and "mostly hiding" are fellow travelers here.
That simple thing she said, to first graders, gave me an utterly different, lifelong, perspective on learning what was being taught and how it was not, perhaps, holy writ.
Still, I like the Oxford comma. By any of its names and descriptions. Except with pandas in restaurants. (Sometimes distinction is the last thing the meaning needs.)
2018-11-26 18:16:56
Steven J. Van Steenhuyse
It appears that Rebecca has not been converted to the Oxford Comma.
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments