Changing format of numbers

Bluemegaman

New Member
Joined
Nov 17, 2005
Messages
7
Hi all,

Having problems with changing the format of some numbers (they're supposed to be telephone numbers!). when exporting into a spreadsheet from our database some of the telephone numbers (but not all!) miss their first zero so in excel they come out in one number like

208XXXXXXX

I Need them like this

020 xxxx xxxx

I have thousands of numbers with this problem. Am in need of some code which will add the zero to the front end of the numbers and then put a space after the third and seventh digit, otherwise excel just deletes the zero again :cry: .

I have tried using the Left function etc but am not very familiar with these as i only started vba last week.

Any help would be very appreciated.

Thanks - :)
Mike
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Harvey

Well-known Member
Joined
Nov 18, 2004
Messages
953
this formula will convert any number to your format. It has to be 11 characters though.

=REPT(0,11-LEN($A8)) & LEFT($A8,3-(11-LEN($A8))) & " " & MID($A8,4-(11-LEN($A8)),4) & " " & RIGHT($A8, 4)
 

Bluemegaman

New Member
Joined
Nov 17, 2005
Messages
7
thanks it would work but my numbers aren't always 11 characters long- some are missing the zero at the front which is why excel is having a problem displying them.

Preferably i need code which would search the numbers and find those without a zero on the front THEN convert them into the xxx xxxx xxxx format.
 

Bluemegaman

New Member
Joined
Nov 17, 2005
Messages
7

ADVERTISEMENT

yes i have tried formatting the cells that way and it does not take unfortunately :cry:
 

Harvey

Well-known Member
Joined
Nov 18, 2004
Messages
953
bluemegaman I meant with my formula the number cannot be longer than 11 characters. Shorter numbers are no problem. As long as you do not use phone numbers with 11+ cyphers you can use my formula.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,052
Messages
5,835,148
Members
430,342
Latest member
Sailingexcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top