Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, 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: Getting Rid of Spaces in Merged Data.

Getting Rid of Spaces in Merged Data

Written by Allen Wyatt (last updated September 26, 2020)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


Chris has a merge field called NHS_Number which brings in a ten-digit number in the format 123 456 7890. He needs to remove the spaces so that the number is displayed as 1234567890. The data comes from a program whose formatting he can't change, and the use of VBA isn't acceptable. Chris wonders if there is something he can do with the fields themselves to get rid of the spaces.

One thing you can try is to modify the merge field so that it contains some formatting code. Expand the merge field (put the insertion point within it and press Alt+F9) and then add the following code just before the closing field brace:

\#0000000000

Note that there are ten zeros in the formatting code. Once the code is added, and with the insertion point still between the field braces, press Alt+F9 again to collapse the field.

You should note that there are several things that could cause this to not work, the chief culprit being that there is something in your data that causes Word to treat the incoming field as text rather than as a number. If the formatting code doesn't work, your only option is to modify the data that is being merged into your Word document.

Even though you may not be able to change the program that is generating the merge data, there is a good chance that the merge data is in some format that can be changed, such as an intermediate Word document or an Excel workbook. If this is the case, simply open the document or workbook and use the Find and Replace capabilities of either program to search for spaces in the field and remove them.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8956) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Getting Rid of Spaces in Merged Data.

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

Getting Rid of Empty Rows after Importing

Import data into a worksheet (or paste it there) and you may find that you end up with a group of blank cells you need to ...

Discover More

Creating Compound Characters

Word provides access to a wide variety of characters either from the keyboard or from the Symbol dialog box. Up and above ...

Discover More

Determining an ANSI Value

You may need to determine the numeric value of a character in a macro. You can do that using the Asc function, described ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Checkboxes in a Merged Document

When creating a mail-merge document, you may want to include some special characters, such as check-marked boxes, in the ...

Discover More

Can't Place Merge Field in Header of a Catalog Merge Document

Word can perform several different types of mail merge operations, and the type you choose can affect how you are able to ...

Discover More

Merging and Printing a Series of Documents

Do you need to merge and print a number of documents in a particular order? Perhaps the best approach is to record a ...

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 two less than 3?

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.