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.

Replacing the Last Comma

Written by Allen Wyatt (last updated March 14, 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:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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.

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

Selective Undo

Ever wonder why you can't undo just a single edit you made a few minutes earlier? The short answer is that it could make ...

Discover More

Automatically Enabling Macros for Specific Workbooks

On your system you may have workbooks that contain macros you know are safe to use. Microsoft provides two things you can ...

Discover More

Updating a Field in a Text Box

If you put a field into a text box, you might be surprised to find that it doesn't update when you try to update all your ...

Discover More

Discover the Power of Microsoft Office This beginner-friendly guide reveals the expert tips and strategies you need to skyrocket your productivity and use Office 365 like a pro. Mastering software like Word, Excel, and PowerPoint is essential to be more efficient and advance your career. Simple lessons guide you through every step, providing the knowledge you need to get started. Check out Microsoft Office 365 For Beginners today!

More WordTips (ribbon)

Using Go To with a Percentage

Need to jump a certain percentage of the way through a document? You can do it using the familiar Go To tab of the Find ...

Discover More

Automatically Identifying Repeated Words

Need to find out how many times words are repeated in a document? If so, you'll appreciate the discussion in this tip ...

Discover More

Locking Paragraphs So They Cannot be Edited

Want to protect certain paragraphs in your document so they cannot be changed? This tip provides a look at three ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 five more than 6?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

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.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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.