Word.Tips.Net WordTips (Menu Interface)

Maintaining Leading Zeroes

Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Maintaining Leading Zeroes.

Suzanne has an Excel worksheet containing addresses. The ZIP Codes are formatted via the special Excel formatting that maintains leading zeroes. However, when she uses mail merge in Word, the leading zeroes are dropped.

There are several ways you can approach this problem. You could, for instance, go into Excel and create a new column that contains text versions of the numeric ZIP Codes. Here's a handy Excel formula to use to accomplish this:

=RIGHT("00000" & A1, 5)

If you put this formula in a column that has been formatted as text (and the ZIP Code is in cell A1), you end up with text that contains the leading zeroes. You can then use this new column in your merge in Word.

If you don't want to edit the original Excel data, then you should stick with making your changes in the Word merge document. Take a look at the document; it contains merge fields that indicate where the merged data will be placed. These fields also indicate how the merged data should be treated. If you select the merge field for the ZIP Code, you can expand it by pressing Shift+F9. You should see the underlying code that makes up the field. You can then modify the field code so it looks similar to this:

{ MERGEFIELD "Zip" \# 00000-0000 }

The name within the quote marks ("Zip") may well be different; it represents the name of the column in the Excel worksheet that needs to be merged. The important part is to add the formatting switch (\#) followed by the pattern to be used for formatting the merged data. When you are done making the change to the field, you can press Shift+F9 again to collapse the field, and then do your merge.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (324) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Maintaining Leading Zeroes.

Related Tips:

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!


Leave your own comment:

  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*What is 5+3 (To prevent automated submissions and spam.)
           Commenting Terms

Comments for this tip:

Scott    23 Oct 2012, 11:09
I have written a vba macro that I use on my excel sheets to fix the zip codes. Highlight the zip code row, and run the macro to format the column to text and add the necessary leading zeroes.

I'm not a VBA expert or an Excel whiz, so there may be further improvements that could be made:


Sub fix_zip()

Dim arrData() As Variant
Dim rng As Excel.Range
Dim lRows As Long
Dim lCols As Long
Dim i As Long, j As Long
Dim reps As Integer
Dim LastRow As Long

' let's not accidently use this on a non-Range object
If TypeName(Selection) <> "Range" Then Exit Sub

lRows = Selection.Rows.Count
lCols = Selection.Columns.Count

LastRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

If lRows > LastRow Then lRows = LastRow

Selection.Resize(lRows, lCols).Select

ReDim arrData(1 To lRows, 1 To lCols)

Set rng = Selection
rng.NumberFormat = "@"
arrData = rng.Value

For j = 1 To lCols
  For i = 1 To lRows
    If Len(Trim(arrData(i, j))) < 5 And Len(Trim(arrData(i, j))) > 0 And Left(Trim(arrData(i, j)), 1) >= 0 And Left(Trim(arrData(i, j)), 1) <= 9 Then
        reps = (5 - Len(Trim(arrData(i, j))))
        For k = 1 To reps
            arrData(i, j) = "0" & Trim(arrData(i, j))
        Next k
    End If
 Next i
Next j

rng.Value = arrData

Set rng = Nothing
End Sub


Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us


Advertise with Us

Our Privacy Policy

Our Sites


Beauty and Style




DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)



Home Improvement

Money and Finances


Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives


Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.