Phone formatting (###)###-####

Mike TheSpike

New Member
Joined
Jul 12, 2021
Messages
40
Office Version
  1. 2010
Platform
  1. Windows
Hi Guys,

Need help in macro for the phone format (###)###-####. Samples phone numbers to be formatted: (123) 456-7890, (123) 456 - 7890, 123 456 - 7890, 1234567890, 123) 456 - 7890, (123 456 - 7890 , +1(123) 456-7890, 1(123) 456-7890
Is it okay to assigned that macro in shortcut key? The way I used my macro is like this I have my macros in fix workbook and another workbook open which is my working file, every time I used shortcut keys(assigned macros) it works in my working file because the workbook where the macros were saved was opened.

Thanks to your amazing skills,
Regards,
Mike
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Another option to try. This also copes with the situation where the user might click the Cancel button on the Input Box.

VBA Code:
Sub Format_Phone_Numbers()
  Dim RX As Object
  Dim Rng As Range, c As Range
  
  On Error Resume Next
  Set Rng = Application.InputBox(Title:="Phone Number Format Range", _
    Prompt:="Select the range (or type the address) of cells to pull into your phone number format rule", Type:=8)
  On Error GoTo 0
  If Not Rng Is Nothing Then
    Set RX = CreateObject("VBScript.RegExp")
    RX.Global = True
    RX.Pattern = "(\+?1\()|\D"
    For Each c In Rng
      c.Value = Format(RX.Replace(c.Value, ""), "(###)###-####")
    Next c
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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