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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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)
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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
Back
Top