Software

Generate a descending-order numbered list in Word

Word can't automatically produce a numbered list that counts down instead of up. But with the help of a bookmark and some fields, you can work around that limitation.

Numbered lists are one of Word's best features. Click a button, type a few items, and like magic, you've got a numbered list. What this feature can't do for you is generate a list of descending numbers. For instance, if you want a Top 10 list, don't try Word's numbering feature. You could enter the numbers manually, but updating such a list is messy. If you insert or delete an item, you must update all the numbers from that item to the end of the list. A more flexible solution is to use a sequential field. Doing so requires a bit of planning, but it's worth it.

Note: This information is also available as a PDF download.

About the sequential field

In Word, the term field refers to special codes that perform specific tasks, such as inserting data, returning values, and so on. In the case of this technique, you can use the sequential field, SEQ, to return a list of sequential numbers. Used in a list, you can add, delete, or move an item and the field code updates automatically.

The sequential field code has one required parameter:

{ SEQ identifier [bookmark ] [switches ] }
where identifier is the name you assign to a series of items you want numbered. This name must start with an alpha character and be 40 characters or less. You can use alpha and number characters and the underscore character to complete the name. Use bookmark to refer to an item somewhere else in the document. In addition, the switches in Table A add flexibility.

Table A

\c Repeats the closest preceding sequential number
\h Hides the field's result
\n Inserts the next sequential number (the default)
\r n Resets the sequence to n
\s Resets the sequence number at the heading level

Using just the SEQ field code, you can create and then sort the results to get a descending list. However, similar to a manual descending list, you must update and resort the list if you insert an item. For example, the short list in Figure A uses SEQ.

list

Figure A: Sort a list of SEQ fields to generate a list of descending numbers.

To create this list, do the following:

  1. Position the cursor where you want to begin the list and choose Field from the Insert menu.
  2. From the Field Names list, choose seq.
  3. In the Field Codes control, add list, as shown in Figure B, and click OK.

seq field

Figure B: Update the SEQ code by identifying the list items.

  1. Enter the first numbered item.
  2. Repeat steps 1 through 4 until you complete the list. Or copy and paste the field instead of manually creating a new one for each item. Don't worry if the copied fields don't generate a sequential list -- they will.
  3. Highlight the entire list and press F9 to update the field codes.
  4. Highlight the entire list (if necessary) and choose Sort from the Table menu.
  5. In the resulting dialog box, click Descending in the Sort By section, as shown in Figure C.

sort by

Figure C: Choose the Descending Sort By option.

Using sequential fields, you don't have to identify the total number of list items, but inserting or deleting items is difficult because the fields won't automatically update. What happens if you highlight the list, press F9, and then resort it? Unfortunately, that won't work the way you might expect. The inserted item made it to the right spot, but the rest of the list, as you can see in Figure D, is in reverse order. If you update the list to generate a new number, Word generates a new list of ascending numbers. A sequential field list is a one-time deal.

wrong order

Figure D: Resorting a sequential field list won't produce the expected results.

A flexible and dynamic sequential field list

Strictly speaking, you can't change a sequential field list. You can, however, combine fields to manage descending lists that might change. The process of creating the fields is a bit tricky, but once the fields are in place, you can alter the list without worry.

Let's create the same descending-order list using a compound sequential field. To do so, you'll need a bookmark and a compound field.

The dynamic list field refers to a bookmarked value that equals the total number of items in the list. Creating a bookmark is easy enough, but in this case, the bookmark must reference that value and not just a random spot in the document. For that reason, you must bookmark the actual value. So find an out-of-the-way spot in the document and enter a value. You don't have to know the exact value at this point, just enter a value and then highlight it. With the value highlighted, choose Bookmark from the Insert menu. Name it DescendingList, as shown in Figure E, and click Add. (You can name the bookmark anything you like; just be sure to reference it correctly in the compound field later.)

bookmark

Figure E: Insert a bookmark for storing the number of items in the list.

Now, if you're supplying this functionality to users via a custom template, you'll probably want to control this value differently. In fact, you might prefer to use a macro that solicits the value from the user and completes the entire listing task. Better yet, let the macro instruct the user to highlight the list and then let the macro do the counting. How you execute this technique is up to you.

Next, you need a compound field. Specifically, this field combines Formula, SEQ, and REF field codes. Creating a compound, or nested, field takes a bit of patience. You begin by inserting the first field code. Then, you position the cursor inside the first field and insert a second field. You repeat the process to add all the necessary field codes. This list technique uses the following compound field:

{ = {REF DescendingList } - {SEQ list * MERGEFORMAT } + 1}

To create the above field, follow these steps, exactly:

  1. From the Tools menu, choose Options, and click the View tab (if necessary). In the Show section, check the Field Codes option. (You need to see the actual field codes to create a compound field.)
  2. Position the cursor where you want to begin the list.
  3. Choose Field from the Insert menu.
  4. Click the Formula button, enter a subtraction operator (-), and click OK.
  5. In the document, position the cursor between the equals operator and the subtraction operator.
  6. Choose Field from the Insert menu.
  7. Choose Ref from the Field Names list.
  8. In the Bookmark Name list, highlight DescendingList, as shown in Figure F, and click OK.

descending list bookmark

Figure F: Reference the bookmarked value named DescendingList.

  1. Position the cursor between the subtraction operator and the field's closing brace.
  2. Choose Field from the Insert menu.
  3. Select Seq from the Field Names list.
  4. In the Field Codes control, add list (see Figure B) and click OK.
  5. Position the cursor between the two closing brackets and enter + 1.
  6. In the document, position the cursor to the right of the field code, type the first list item, and press Enter. You won't sort this list, so keep in mind that the first item is really the last item and enter items accordingly.
  7. Insert a new field by repeating steps 2 through 11 or copy and paste the field.
  8. Enter the second list item and continue in this manner until you've created the list shown in Figure G.

finished list

Figure G: Our list of compound fields and items is complete.

Go ahead and select the list and press F9 to update it. Then, since Word is still displaying field codes instead of values, choose Options from the Tools menu, click View, and deselect the Field Codes check box.

Unfortunately, as Figure H shows, this list isn't the right list! This field, while flexible, is a bit stupid -- it can't differentiate from the earlier list and the new one. In this case, the solution is easy. Delete the first list. Then, highlight the new list and press F9 to update it. As you can see in Figure I, the field now returns the expected descending list.

wrong list

Figure H: This compound field is fine, but it's placement following a previous field list is problematic.

fixed list

Figure I: A compound field returns sequential numbers in descending order.

Unlike a manual list or a lone SEQ field, this list is easy to update. For instance, insert a new line anywhere in the list. Then, copy and paste a field code from an existing item to the new line and enter a new item. (Don't worry if the number isn't correct.) Highlight the entire list and press F9 to renumber the entire list, as shown in Figure J.

updated list

Figure J: We added an item to the list and updated the fields.

Look at the list carefully. Notice that although there are six items, the list still starts with the number 5. That's as designed and not a mistake. Word doesn't care that there are more or fewer than five items. The compound field begins with the bookmarked value and descends accordingly. If you want the list to start number with the number 6, as shown in Figure K, update the bookmarked value, highlight the list, and press F9.

adjusted bookmark

Figure K: Adjusting the bookmark value returns the desired results.

Dynamic descending list

Since Word can't automatically generate a descending-order numbered list, you'll have to do it yourself. Fortunately, you don't have to jump through too many hoops: Create a compound field, update the list, and start counting backward!


Susan Sales Harkins is an independent consultant and the author of several articles and books on database technologies. Her most recent book is Mastering Microsoft SQL Server 2005 Express, with Mike Gunderloy, published by Sybex. Other collaborations with Gunderloy are Automating Microsoft Access 2003 with VBA, Upgrader's Guide to Microsoft Office System 2003, ICDL Exam Cram 2, and Absolute Beginner's Guide to Microsoft Access 2003, all published by Que. Currently, Susan volunteers as the Publications Director for Database Advisors. You can reach her at ssharkins@gmail.com.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

0 comments