Word: Delete tabs and page numbers from the end of a paragraph

February 13, 2012

One of my colleagues wanted me to grab all the tables of contents (TOCs) out of 18 separate chapters of a really long report and put them in a single document that she could share with the stakeholders. She only wanted the outline numbering and the heading titles, down to three TOC levels.

I copied each table of contents and pasted it as plain text into a new document. That preserved the outline numbering, followed by a tab, then the heading title, but it also added a tab after the heading title and the page number, neither of which were required. As the plain text version of the 18 chapter TOCs came to well over 12 pages (!), there were several hundred lines, one for each TOC entry. I could manually delete these tabs and page numbers, but that was going to get very tedious very quickly.

What I wanted was a single command to get rid of the end tabs followed by the page number. But I needed to keep the tabs after the outline numbers.

Find and replace wildcards to the rescue!

My first attempt only found the single digit page numbers and replaced them, so I tested a bit more to find a way to delete page numbers no matter what their length.

Here’s how:

  1. Open Word’s Find and Replace dialog box (Ctrl+H).
  2. Click More to show more options.
    Find and Replace dialog - click the More button
  3. Select the Use wildcards check box.
    Find and Replace dialog - select Wse Wildcards
  4. In the Find what field, type: (^t)([0-9]*)(^13)
    Note: There are NO spaces in this string, the t must be lower case, and there’s an asterisk (*) immediately after [0-9] bit.
  5. In the Replace with field, type: ^p
    Note: The p must be in lower case.
    Replace tab and page number with paragraph mark
  6. Click Find Next, then click Replace to test that it works fine. If so, click Replace All.

Explanation for how this works:

  • (^t) looks for a tab character; you MUST use a lower case t and precede it with the ^ (Shift+6). Because you are using wildcards, you need to surround the characters you want to find in parentheses.
  • ([0-9]*) looks for any numeral of any length that follows immediately after the tab character. The square brackets indicate a range — in this case any numeral from 0 to 9 will be found. And the asterisk looks for any number of characters that are in the range of 0 to 9 (this finds all the one, two, three etc. digit page numbers).
  • (^13) looks for the paragraph marker immediately following the page number. Note: When using wildcards you can’t use the usual ^p for the paragraph marker — you MUST use ^13 (the control code for a carriage return). See: http://office.microsoft.com/en-us/word-help/find-and-replace-text-or-other-items-HA001230392.aspx#_Toc282602054
  • ^p in the Replace field replaces everything found (the tab followed by the page number[s] followed by the paragraph mark) with a paragraph mark, effectively deleting the tab and page number(s).

It worked like a charm! My colleague was super impressed and I learned something new — can’t ask for more than that!

[Links last checked February 2012]

One comment

  1. Nice article. I’ve been using this tricky, sneaky, and darned effective technique for some 15+ years.

    Why MS doesn’t emphasis it more I do not know. It saves so much time & effort on the picky little layout, look /n feel things.

    Thanks again. And, yes, I bought you a coffee.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: