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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,211,879
Messages
6,104,535
Members
447,914
Latest member
karl10220

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