Routine #12 from our series of text subroutines to use in EXCEL to extract all the alphanumeric characters. Everything that does not fall under alphanumeric character will be automatically removed from the selected cells content.
Code snippet below:
Sub AlphaNumericOnly() 'Keep only alphanumeric characters Dim selected_range As Range Set selected_range = Range(Selection.Address) Dim i As Integer Dim strResult As String Dim old_value As String For Each cell In selected_range old_value = vbNullString: old_value = cell.Value For i = 1 To Len(old_value) Select Case Asc(Mid(strSource, i, 1)) Case 48 To 57, 65 To 90, 97 To 122: 'include 32 if you want to include space strResult = strResult & Mid(strSource, i, 1) End Select Next cell.Value = strResult Next
You can see how to add this to Excel in order to use the code in this thread UPPER CASE