Search & delete ANY text in select columns

H

huruta

I import statistical results from another program (Stata) and with i
comes text that I want to get rid of. Specifically in select columns
want to erase any text in those columns. I'm just not sure how t
identify "any text" when I do my search and replace for the selecte
columns. Any help?

Thank you
 
G

Gord Dibben

Select your columns then run this macro.

Sub RemoveAlphas()
'' Remove alpha characters from a string.
'' except for decimal points
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
 
Top