Excel 2010 – how to prepend a “0” to make an 8 digit number 9 digits

microsoft excelmicrosoft-excel-2010

I'm running Excel 2010 using a output file from our database software that exports a list of our affiliate stores. The affiliate stores have a 9 digit code and a number of these codes start with "0".

When this column is converted from text to numbers, Excel removes the initial digit if it starts with "0" and the result is that the 9 digit number becomes an 8 digit number. Is there a way to prepend a "0" to a number in a cell?

The ultimate goal is to run a script on these codes as the first 4 digits represent the region where the affiliate store is.

Best Answer

2 ways of looking at this:

1) You simply want to see the number displaying 9 digits. In this case:

Go to Format Cells > Custom. Under Type, input "000000000" where there used to be "General" to set minimum number of digits displayed = 9

2) You need to verify with the first 4 digits:

To convert the number to a string, use the TEXT() Function:

    Value = 2

TEXT(Value, "00") = 02

To completely solve your question, simply obtain the first four digits by

   =(LEFT(TEXT(Value, "000000000"),4)

Good luck.