Search This Blog

Saturday 19 June 2010

Word: Adding thousands separators

Instead of just typing the number, choose Insert | Field (Word 2007 users will choose Quick Parts | Field from the Insert ribbon). Select the very first item, titled = (Formula) and click the Formula... button. Type your number here following the = in the first box, then select the number format #,##0.00 and click OK. Your number will appear nicely formatted.
If you need to change the value later, click on the number, press Shift-F9 to show the field codes, make the change, and then press Shift-F9 to switch back to showing the field value (if you don't see the change right away, press F9 to update the field). Yes, this is an extra effort, but there's no simple way to apply the formatting the way you can in Excel.
Of course, you still need to fix up the existing numbers, and to do that you first need to find them. Suppose you want to change all numbers consisting of 6 to 12 digits followed by a decimal point and 2 digits. Press Ctrl-F for Find, click the More button, and check the Use wildcards box. In the Find what area at top, enter <[0-9]{6,9}.[0-9]{2. Do not include the period at the end of the preceding sentence.
Here's how this odd string of wildcards breaks down:

< [0-9]
{6,12}
[0-9] {2}
beginning of a word any character from 0 to 9
from 6 to 12 occurrences of whatever came immediately before a plain old decimal point
any character from 0 to 9
exactly two occurrences of whatever came immediately before
When you click Find Next, the first matching number will be highlighted. Leave the Find dialog box open and switch back to the main document. Press Ctrl-F9 to convert the highlighted text into a field. Insert an equal sign right before the number, then a space and \# "#,##0.00" (including the quotes) after the number but before the ending bracket. Press Shift-F9 to toggle from viewing field codes to viewing the number itself. Now switch back to the Find dialog, find the next number, and repeat.