Phone number formating

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
426
Office Version
  1. 2019
Platform
  1. Windows
Hi
I have a userform which places a phone number into a sheet, I would like to enter the number without spaces and have it automatically formatted when entered into the sheet. My problem is some numbers need to be formatted as 020 8765 1234 and some in the format 01777 123456. All numbers will either start 01 or 02. Is this possible please.
Thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
example
srcResult
0123456789001234 567890
02 457 65 98 12024 7659 9812
01 4567 657 8901456 765789

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Replace = Table.ReplaceValue(Table.TransformColumnTypes(Source,{{"src", type text}})," ","",Replacer.ReplaceText,{"src"}),
    Result = Table.AddColumn(Replace, "Result", each if Text.Start([src], 2) = "01" then Text.Start([src], 5)&" "&Text.End([src], 6) else Text.Start([src], 3)&" "&Text.Middle([src], 4, 4)&" "&Text.End([src], 4)),
    TSC = Table.SelectColumns(Result,{"Result"})
in
    TSC
 
Upvote 0
Solution
Book1
CD
4Sourceresult
52087771234020 8777 1234
6178912345601789 123456
Sheet1
 
Upvote 0
your source starts with 2 or 1 not 02 or 01
anyway if I add 0 at the start of the string the result is
srcResult
0123456789001234 567890
02 457 65 98 12024 7659 9812
01 4567 657 8901456 765789
02087771234020 7771 1234
0178912345601789 123456

so assumption: your source column should be formatted as text before enter the phone number
 
Last edited:
Upvote 0
source column should be as text, the result is as text also
phone "number" format is changed by M code as you can see in post #3

I suggest to update your profile (Account details) about Excel version and OS
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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