h1

Word: Add a character to all items in a long list, and style it in a colour

July 27, 2018

Here was a tricky one posed by my husband first thing this morning. He had a very long column in a table (some 2750+) rows, in which he had some sort of code, like a product identifier. Fortunately, the codes were all the same — they were all K-xxxx, where ‘xxxx’ was a 4-digit number (e.g. K-1234, K-5432, etc.).

He wanted to add a zero immediately after the hyphen. Easy enough. But he wanted this zero character to be blue! Hmmm… (and no, I have no idea why! Update: He had a list of catalogue numbers, but when the company used up all the 4-digit numbers, they changed to 5-digit numbers. To sort them correctly by catalogue number in Word, he needed to add a leading 0 to the 4-digit ones, but he wanted to show that the 0 wasn’t part of the original number, thus the colour.)

After a few minutes of testing I achieved what he wanted. I had to do three find and replace passes, with one of them a wildcard find/replace — the first pass added the 0, the second changed the colour of the hyphen and its trailling zero to blue, and the third changed the colour of the hyphen back to black, leaving just the 0 after the hyphen in blue text.

NOTE: If you’re doing something like this on your own document, either work on a COPY until you’ve refined the procedure and know you won’t inadvertently replace something you shouldn’t have, OR at the ‘Replace All’ steps below, click ‘Replace’ instead, followed by ‘Find Next’. You will have many more clicks to do, but it’s a safer option.

Here’s what I did:

First pass – add a zero after the hyphen:

  1. Open the Find/Replace window (Ctrl+H).
  2. In the Find What field, type K-
  3. In the Replace With field, type K-0
  4. Select the list (or column in a table) you want to apply this change to
  5. Click Replace All. This adds a zero after the K-, so you end up with codes like K-01234, K-05432, etc.
  6. Leave the Find and Replace window open.

Second pass – make the hyphen and the zero another colour:

  1. For the second pass, click outside the selection to position the cursor away from it (I had to do this because as soon as I entered the wildcard string for the colour, ALL the selected text changed to blue, without me even clicking Replace All — very strange).
  2. In the Find/Replace window, click More.
  3. Select the Use wildcards checkbox.
  4. In the Find What field, type (-)(0) (there are NO spaces in this string).
  5. In the Replace With field, type \1\2 (there are NO spaces in this string).
  6. With your cursor still in the Replace With field, click Format.
  7. Select Font.
  8. Choose a colour from the Font color drop down.
  9. Click OK.
  10. Check the Replace With field — it should have Font color: <name of colour> below the field. The only thing below the Find What field should be Use wildcards. If you have something different, repeat these steps, and make sure you follow Step 6 exactly.
  11. Select the list (or column) again.
  12. Click Replace All. This changes the hyphen and trailling zero to the colour you selected.
  13. Leave the Find and Replace window open.

Third pass – remove the colour from the hyphen:

  1. For the third and final find and replace pass, click outside the selection to position the cursor away from it. Don’t forget to do this!
  2. Clear the Use wildcards checkbox.
  3. In the Find What field, delete the existing characters, then type a hyphen.
  4. In the Replace With field, delete the existing characters, then type a hyphen.
  5. With your cursor still in the Replace With field, click Format, select Font, then in the Font Color drop-down box, select Automatic (or another font colour).
  6. Select the list (or column) again.
  7. Click Replace All. This changes the hyphen colour to the colour you selected in Step 5.

 

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: