Extract Alphanumeric characters

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

2 thoughts on “Extract Alphanumeric characters

  1. Aw, this was an exceptionally good post. Taking the time and actual effort
    to make a superb article… but what can I say… I put things off
    a whole lot and never manage to get anything done.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>