-8

I have large data set - 10 000 records with the phone numbers:

Phone_N
5656666666
6676767677
6767677777
5555555555
5555567888
6666777777

I need to format it like:

Phone_N
(565) 666-6666
(222) 767-3333
(676) 777-7777

etc....

My data already have no spaces, "-", "/" or any other characters.

It just needed to be formatted in a proper phone format.

It would be very helpful if you could point me the right direction to start.

4

4 回答 4

8

You can use the Format Function to format Phone_N as you wish. I'm not sure whether Phone_N is text or numeric data type, but the following Format example will accept either.

Phone_N = 2227673333 ' (Phone_N is numeric)
? Format(Phone_N, "(###) ###-####")
(222) 767-3333
Phone_N = "2227673333" ' (Phone_N is text)
? Format(Phone_N, "(###) ###-####")
(222) 767-3333
于 2013-09-26T15:09:30.690 回答
2

You could use a UDF (user defined function)

stick the below code in a standard module in VBE (Visual Basic Editor) ALT+F11 right click anywhere in the Project Explorer window » Insert » Module

after formatting use ADO to UPDATE your table

Function FORMAT_NUMBERS(r As Range)
    FORMAT_NUMBERS = "(" & Left(r, 3) & ") " & Right(Left(r, 6), 3) & "-" & Right(r, 4)
End Function

example

enter image description here

于 2013-09-26T15:21:27.760 回答
1

no need to use VBA, just try Notepad++, edit your data in cloumn pattern.

于 2013-09-26T06:14:28.463 回答
0

This can be done in VBA. You could use the following to accomplish this.

Dim rs As DAO.Recordset, TempN As String
Set rs = CurrentDb.OpenRecordset("SELECT Phone_N FROM MyTableName", dbOpenDynaset)

If (rs.RecordCount <> 0) Then
  rs.MoveFirst
  Do While rs.EOF <> True
    TempN = rs.Fields("[Phone_N]").value
    rs.Edit
    rs.Fields("[Phone_N]").value = "(" & Left(TempN, 3) & ") " & _
                                   Left(Right(TempN, 7), 3) & "-" & _
                                   Right(TempN, 4)
    rs.Update
    rs.MoveNext
  Loop
End If
于 2013-09-26T13:55:20.840 回答