Convert Function to Sub
Sub CleanChars()
Dim CL As Range
Dim x As Long
Dim sChar As String
Dim ExtractNT As String
Application.ScreenUpdating = False
For Each CL In Selection.Cells
ExtractNT = vbNullString
For x = 1 To Len(CL)
sChar = Mid(CL, x, 1)
If sChar = "0" And sChar <= "9" Or sChar Like "[a-zA-Z]"
Then
ExtractNT = ExtractNT & UCase(sChar)
End If
Next x
CL.Value = ExtractNT
Next CL
End Sub
"Paige" wrote:
I have the following function which is used to extract the numeric and alpha
characters from a cell. Can someone help me 'convert' this to a sub, so
that, for example, with whatever range the user selects, the code will look
at each cell and basically remove everything that is not either alpha or
numeric? Example:
45 BJ}!12T would be converted to 45BJ12T
Public Function ExtractNT(TextString As String) As String
Dim x As Long
Dim sChar As String
ExtractNT = vbNullString
For x = 1 To Len(TextString)
sChar = Mid(TextString, x, 1)
If sChar = "0" And sChar <= "9" Or sChar Like "[a-zA-Z]" Then
ExtractNT = ExtractNT & UCase(sChar)
End If
Next x
End Function
|