Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Remove Dashes

I have about 4,000 cells in Excel 200 that have phone numbers formatted as
(123)456-7890. I would like to remove everything except the numbers so that
they come out like 1234567890, what is a good way to do this?

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Remove Dashes

Here is one method using VBA.

Sub RemoveAlphas()
' Remove alpha characters from a string.

Dim intI As Integer
Dim rngR As Range, rngRR As Range
Dim strNotNum As String, strTemp As String
Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _
xlTextValues)
For Each rngR In rngRR
strTemp = ""
For intI = 1 To Len(rngR.Value)
If Mid(rngR.Value, intI, 1) Like "[0-9]" Then
strNotNum = Mid(rngR.Value, intI, 1)
Else: strNotNum = ""
End If
strTemp = strTemp & strNotNum
Next intI
rngR.Value = strTemp
Next rngR
End Sub


Gord Dibben MS Excel MVP


On Thu, 10 Aug 2006 17:34:11 -0700, "Striker" wrote:

I have about 4,000 cells in Excel 200 that have phone numbers formatted as
(123)456-7890. I would like to remove everything except the numbers so that
they come out like 1234567890, what is a good way to do this?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Remove Dashes


Striker wrote:
I have about 4,000 cells in Excel 200 that have phone numbers formatted as
(123)456-7890. I would like to remove everything except the numbers so that
they come out like 1234567890, what is a good way to do this?

Thanks


Here is a custom function that will do the trick for you. Create a new
Module in the VBE and enter the following code:

Function CleanNumbers(OldNumbers As Range) As String

Dim CurChr, OldStr As String
Dim Cnt As Integer

OldStr = OldNumbers
Cnt = 1
Do Until Cnt Len(OldStr)

CurChr = Mid(OldStr, Cnt, 1)
If IsNumeric(CurChr) = True Then
CleanNumbers = CleanNumbers & CurChr
Debug.Print CleanNumbers
End If
Cnt = Cnt + 1
Loop

End Function

if A1 has the following number --- (123)456-7890
and you use the formula: =CleanNumbers(A1) in cell A2
then A2 will display: 1234567890

Have fun....

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Remove Dashes

here's one way taht may work for you

Sub test()
Dim cell As Range
For Each cell In Range("a1:a4000")
cell.Value = Replace(Replace(Replace(cell.Value, "(", "", 1), ")", "", _
1), "-", "", 1)
Next
End Sub

--


Gary


"Striker" wrote in message
...
I have about 4,000 cells in Excel 200 that have phone numbers formatted as
(123)456-7890. I would like to remove everything except the numbers so that
they come out like 1234567890, what is a good way to do this?

Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create a formula to remove dashes? jackierae17 Excel Discussion (Misc queries) 5 May 5th 10 03:04 PM
Remove dashes from phone numbers in a spreadsheet AAH Excel Worksheet Functions 3 July 25th 08 05:50 AM
Why do the preceding zeros disappear when I remove dashes? carridin1 Excel Discussion (Misc queries) 3 June 5th 07 11:19 PM
how to remove dashes [email protected] Excel Worksheet Functions 2 February 28th 07 09:55 AM
remove the ( ) & dashes from column of phone # alvie Excel Worksheet Functions 2 July 2nd 06 04:32 PM


All times are GMT +1. The time now is 12:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"