Another approach is to use a UDF which works just like a function in a formula. To use the UDF below:
=RemoveNonNumericChars(A1)
Add this code to any general code module:
Public Function RemoveNonNumericChars(ByVal Value As String) As String
' Remove all non-numeric characters from the parameter.
Dim Result As String
Dim Index As Long
RemoveNonNumericChars = Value
Result = ""
For Index = 1 To Len(Value)
If Mid(Value, Index, 1) Like "#" Then
Result = Result + Mid(Value, Index, 1)
End If
Next Index
If Result <> Value Then
RemoveNonNumericChars = Result
End If
End Function
To add VBA code to a regular or general module in an Excel workbook, press ALT+F11 to open the VBA development environment (VBE). Select the menu command Insert->Module to create a new VBA module. Paste the code into the document window that appears. Press ALT+F11 to return to the Excel workbook.
Kevin