Thursday , 27 June 2019

# Pro tip: Calculate the current page number within a section in Word

Word supplies a number of fields that make most page
numbering schemes easy to implement, but there’s a definite hole. That hole is
the current page position within a section. You can use the {PAGE} field and
restart numbering at the beginning of the section, but only if you don’t also
want to return the current page position within the document. {PAGE} will do
both, but not in the same document. When you need the current position within
both the section and the document, use {PAGE} for the document and add
bookmarks to calculate the section.

If you’ve never worked with Word fields before, you might
want to view the tutorial
before you continue with this technique.

A free example Excel worksheet is provided as an educational aide for this article.

## What happens

A picture’s worth a thousand words, so let’s use pictures to
show what can happen when trying to track page numbers within a section and a
document. The figure below shows a six-page document that we’ll divide into
three sections. The header contains the following text and fields:

```Page {PAGE} of {NUMPAGES}

Page {PAGE} of {SECTIONPAGES} of {SECTION}```

The fields work as follows:

• {PAGE} returns the current page position within the
document or a section.
• {NUMPAGES} returns the total number of pages in the
document.
• {SECTIONPAGES} returns the total number of pages in the
section.
• {SECTION} returns the section number.

Now, let’s see what happens when you add the section breaks.
To add the first section break, position the cursor before the text on the
first page of the second section (page 3). Click the Page Layout tab and choose
Continuous from the Breaks dropdown in the Page Setup group. Then, add another
page break to the first page of the third section (page 6).

At this point, the document values are correct and have been
from the beginning. The section numbers and the total number of pages in each
section are correct. The only thing wrong is the current page in each section.

Also
read: 10 steps to setting up page numbering in Word sections

## The solution

The solution is to add a bookmark to the end of each
section. Then, you use an expression that subtracts the bookmark’s page
position from the current page’s position. The result will be the page position
within the section. For example, section two starts on page 3. We’ll add a
bookmark to the end of page 2: page 3 subtract page 2 = page 1, page 4 subtract
page 2 = page 2, and so on.

Positioning the bookmark isn’t critical, but you’ll need one
on the last page of each section. We’ll name them S1 and S2 for sections 1 and
2, respectively. Now, let’s add S1 as follows:

1. Position the cursor on the last page of section 1. In this
case that’s page 2. Bookmarks are easier to work with if you select text,
so select the word one at the end of the sentence on that page.
2. Click the Insert tab. In Word 2003, choose Bookmark from
3. Click Bookmark in the Links group.
4. In the resulting dialog, enter S1 for the bookmark’s name.

Repeat steps 1 through 5 to add a bookmark to page 5. In
step 1, select the word two. In step 4, name the bookmark S2.

section two: {={PAGE} – {PAGEREF S1}}. Specifically, you’ll modify the section
header for the first page in section two. Before doing so, be sure to unlink
sections one and two.

If you don’t know how to add fields, do the following:

1. Open the header for the first page in section two – that’s
page 3 – by double-clicking the header area on page 3. Make sure you’re on
the right page!
2. Break the link between sections 1 and 2 by clicking the
Link To Previous option in the Navigation group on the contextual Design
tab. (This is where people who scan instead of read the article will miss
a crucial step.) In Word 2003, this option is on the contextual Header and
Footer toolbar.
3. Select the first 3 in the section line – it’s a {Page}
field.
4. Press [Shift]+F9 to display the field instead of its
results.
5. Select the field and press [Ctrl]+F9 to insert a blank
field. It will look selected because the background is gray, but you must
actively drag across it. You should see {{PAGE}}. If you see {}{PAGE}, delete
the empty field, highlight {PAGE} and try again. You can also enter fields
via the Insert tab. Click Quick Parts in the Text group and choose Field.
6. Between the first two opening bracket characters, enter =.
7. Between the two closing brackets, enter -.
8. Following the – character, press [Ctrl]+F9 to enter a new
blank field. At this point, you should see {={PAGE}-{}}.
9. In the blank field, enter PAGEREF S1.
10. Select the entire expression and press [Shift]+F9 to
display the expression’s results – 1.

Repeat the above process for the third section. Be sure you
are on page 6 and unlink the headers (step 2 above). Then, highlight the
expression and press [Shift]+F9. Replace the S1 reference with S2. Highlight
the entire expression and press [Ctrl]+F9.

## Caution!

This technique is complex and there are lots of spots where
compare your work to the demo file to see where your file differs. Here are a
few pitfalls you’ll want to avoid:

• When working with the fields and field expressions, you
must highlight the entire field or expression. I’m referring to the
[Ctrl]+F9 and [Shift]+F9 steps for entering and calculating fields.
• Be sure you’re working on the right page when inserting breaks,
bookmarks, and altering the headers. It’s easy to get lost.
• If the {PAGEREF} field returns an error, you’ve probably
referred to a bookmark that doesn’t exist. Create the missing bookmark and
try the expression again. If the bookmark exists, make sure you referred
to by name (check for typos).
• Don’t forget to break the links between the first and
second sections and the second and third sections.

When applying this to your own documents, I recommend that
you complete the document in full before adding this numbering scheme. Working
around the bookmark positions and references will be difficult at best. In
addition, click Show/Hide in the Paragraph group on the Home tab to see the
exact placement of your section breaks if things don’t flow right. The figures
don’t show these codes, but having them visible while you work is helpful.