Word: Insert a zero in front of single digit numbersJanuary 14, 2014
If you don’t use Word’s auto numbering and you copy numbered content from another source (e.g. an Excel spreadsheet), you may end up with something like this:
If you sort on the first column and don’t specify that it’s a Number column type, you could end up with something like this, where 10, 11 etc. come after 1 and not after 9:
In such circumstances you may want to add a zero in front of the single-digit numbers so that you can sort them properly. While you can do this manually, which is quick and easy if you only have a few, that becomes tedious if you have many tables or lists in your document that have a mix of one- and two-digit manual numbers and you want to change all the single-digit numbers to two-digit numbers, with a zero in front, like this:
Enter Find and Replace using wildcards!
What you’re going to do is look for any single-digit number followed by a period, and then add a zero to the front of the number while keeping the number and its trailing period.
- Select the table column or paragraphs that contain the numbers you want to change. (See NOTE below about this selection.)
- Press Ctrl+H to open the Find/Replace window on the Replace tab.
- Click More.
- Select the Use wildcards check box.
- In the Find what field, type this: (<[0-9])(.) (Note: make sure you type this exactly as written — you might find it easier to copy/paste this instead.)
- In the Replace with field, type this: 0\1\2 (Note: the first character is a zero.)
- Click Replace All.
- When asked if you want to search the remainder of the document, click No (unless of course you really do want to replace all instances of a single-digit number followed by a period in the rest of the document!)
- Thank me by donating to this blog if I’ve just saved you a heap of time ;-)
Explanation for what the wildcards mean:
- (<[0-9]): Find a range ( ) starting with (<) a single number between 0 and 9 [0-9]
- (.): followed by a period
- 0: Replace with a zero
- \1: followed by whatever was found in the first range (the single number)
- \2: followed by whatever was found in the second range (the period)
NOTE: There’s a quirk in Find/Replace whereby Replace All replaces across the entire document if you click Replace or Find Next first. See this blog post for details: https://cybertext.wordpress.com/2014/01/13/word-replace-all-doesnt-work-on-selected-text-only/
[Link last checked January 2014]