WD: Numbers Containing Hyphens Are Sorted Incorrectly

Last reviewed: February 18, 1998
Article ID: Q117156
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows NT, version 6.0
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Microsoft Word 97 for Windows
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a
  • Microsoft Word 98 Macintosh Edition

SYMPTOMS

In some cases, Word may sort numbers incorrectly.

Case 1

When you perform a numeric sort operation on numbers that contain hyphens, such as social security numbers, phone numbers, and nine-digit ZIP Codes (postal codes), Word may sort the numbers incorrectly.

Case 2

Similarly, Word may sort your mail merge data incorrectly when you sort mail merge data records by using the Sort Records tab in the Query Options dialog box (Word 6.0 and later).

CAUSE

Case 1

If you select Number for the Sort By Type setting in the Table Sort Numbers dialog box (in Word 2.x, select Numeric for the Key Type setting in the Sorting dialog box), Word treats the hyphen as a minus sign. As a result, Word performs a subtraction operation and then sorts the difference. For example, if you sort the following list of nine-digit ZIP codes, Word performs a subtraction operation and then sorts the result.

   Nine-Digit ZIP Code               Result If Subtracted
   ------------------------------------------------------

   11111-1111                        10000
   99999-9999                        90000
   95000-0001                        94999
   98000-9999                        88001

   Result of Sorting as Number       Number Used for Sorting
   ---------------------------------------------------------

   11111-1111                        10000
   98000-9999                        88001
   99999-9999                        90000
   95000-0001                        94999

Case 2

Similarly, in a mail merge operation, if you perform a sorting operation based on a field that contains hyphenated numeric data, Word automatically treats your data as numeric and, therefore, uses the hyphen as a minus sign. (To sort from a mail merge operation, open the Mail Merge Helper and then click Query Options.)

NOTE: Word treats the data in any mail merge field as numeric if the first character in the field is a number.

WORKAROUNDS

Method 1: Sort as Text

To correctly sort numbers that contain hyphens, select Text as the Sort By Type setting in the Table Sort Numbers dialog box (in Word 2.x, select Alphanumeric for the Key Type setting in the Tools Sorting dialog box).

Method 2: Sort Data File Before Merging

For a mail merge operation, if you want to sort based on a field that contains hyphenated numbers, sort the data source before you perform the mail merge operation instead of using the Mail Merge Helper.

Method 3: Replace Hyphens Before You Sort the Data

If you want to sort hyphenated data and use the Number (Numeric) Type setting, follow these steps:

  1. Before you perform the sorting operation, replace the hyphens with periods (.).

  2. Sort the data using the Mail Merge Helper (Word 6 and later) or the Sort Text command on the Table menu (the Sorting command on the Tools menu in Word 2.x).

  3. Replace the periods with hyphens to restore your original numeric data.

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

REFERENCES

"Microsoft Word User's Guide," version 6.0, pages 670-671, 689-690


Additional query words: incorrect calculates hyphenated hyphenation
mailmerge math mathematical merge numbers numeric print subtracts working
wrong
Keywords : kbmerge macword winword winword2 word6 word7 word8 word95 word97 wordnt macword98
Version : MACINTOSH: 6.0, 6.0.1, 6.0.1a, 98; WINDOWS: 2.x 6.0, 6.0a, 6.0c, 7.0, 7.0a, 97
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 18, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.