Restore the lost zero in a phone number

Turn 2079460123 into 02079460123 when you know the width is 11.

What you'll make

In Excel: 2079460123, width 11 becomes 02079460123.

The formula

The formula, with a numbered bracket under each part.
NumberPartWhat it doesResult so far
1AND( … )Checks for a whole number that fits the width.TRUE
2REPT("0",B8)Makes a pattern of zeros, one per digit."00000000000"
3TEXT(A8, … )Writes the number in that pattern, adding zeros in front."02079460123"
4"Review phone width"What the cell says for anything else.Not used for row 8
5IF( … )Gives part 3 when part 1 is TRUE, otherwise part 4."02079460123"

Parts 2 and 3 work from the inside out. The result is text, so the zero stays. The numbers here are made-up.

=IF(AND(ISNUMBER(A8),A8>=0,A8=INT(A8),LEN(TEXT(A8,"0"))<=B8),TEXT(A8,REPT("0",B8)),"Review phone width")

How to use it

Yellow bar at the top? Click Enable Editing.

  1. See it work. The Example tab shows 20 made-up examples with the formula already in.
  2. Use your own numbers. Paste numbers and widths into the green columns of the Template tab. The phones fill in by themselves.
  3. Move them into your letter. Copy the results. Then use Paste Special and choose Values.

Before you send

Use this only when your source says every number had this width. It can't guess a width for you.

Microsoft's help: TEXT function