Ron,
I didn't think my original Like statement line was all that bad
Code:
If Mid(CellVal, Z, 1) Like "[!0-9]" Then Mid(CellVal, Z, 1) = " "
however we could have used this statement in its place instead...
Code:
If InStr("0123456789", Mid(CellVal, Z, 1)) = 0 Then Mid(CellVal, Z, 1) = " "
Actually, in thinking about it, the InStr statement is probably a touch faster than the Like version. Here is my original macro using Instr instead of Like...
Code:
Sub RemoveNonDigits()
Dim X As Long, Z As Long, LastRow As Long, CellVal As String
Const StartRow As Long = 1
Const DataColumn As String = "A"
Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, DataColumn).End(xlUp).Row
For X = StartRow To LastRow
CellVal = Cells(X, DataColumn)
For Z = 1 To Len(CellVal)
If InStr("0123456789", Mid(CellVal, Z, 1)) = 0 Then Mid(CellVal, Z, 1) = " "
Next
With Cells(X, DataColumn)
.NumberFormat = "@"
.Value = Replace(CellVal, " ", "")
End With
Next
Application.ScreenUpdating = True
End Sub
And, this InStr version can be used in my UDF as well...
Code:
Function TextNum(ByVal Txt As String, Optional Ref As Boolean = False) As String
Dim X As Long, CellVal As String
For X = 1 To Len(Txt)
If InStr("0123456789", Mid(Txt, X, 1)) > 0 = Ref Then Mid(Txt, X, 1) = " "
Next
TextNum = Replace(Txt, " ", "")
End Function
There, no Like operator... I guess that is better then, right?