need macro to clean up telephone numbers
This is not a macro it is a function. It goes in a standard module:
from the worksheet open VBE:
ALT-F11
from VBE open a fresh module
ALT-I
ALT-M
paste the function in and close the VBE window.
In the worksheet use it like:
=num_part(A14)
In a function, the range is passed as an argument. For example:
=SUM(A2:A50)
the range is A2:A50.
If you have more questions or problems, just update this post.
--
Gary's Student
gsnu200704
"guillermo.ht" wrote:
I don't quite know what to do with this. This does not compile as an Excel
VBA macro, and I don't understand where you specified the range.
"Gary''s Student" wrote:
How about:
Function num_part(r As Range) As Double
v = r.Value
l = Len(v)
v2 = ""
For i = 1 To l
vt = Mid(v, i, 1)
If vt Like "#" Then
v2 = v2 & vt
End If
Next
num_part = v2 * 1
End Function
--
Gary's Student
gsnu200704
"guillermo.ht" wrote:
I have two columns (A:B) of data in my spreadsheet where people enter
telephone numbers. To enforce the integrity of the data in these columns, I
need a macro that will select columns A:B and remove all non-numerical
characters. 0-9 is all I want. I need to remove spaces and the a host of
other things such as dash, slash, dot, and parenthesis.
I have a macro that trims the leading spaces, and runs through a long
find/replace routine, but I wondered if there is a more graceful and better
way to remove everything that isn't a number 0-9 from these range of cells.
For example: 919-123-4567 or 919.123.4567 would become 9191234567
Any suggestions?
|