I need to run the following code on non-contiguous columns, There is code posted here on how to do this for a different piece of code. Add loop to vba code for excel
I Need to do the same for:
Sub CleanAll()
Dim rng As Range
For Each rng In Sheets("Sheet1").Range("D2:D100").Cells 'adjust sheetname and range accordingly
rng.Value = TextOnly(rng.Value)
Next
End Sub
My failed effort
Sub CleanAll(sColRange As String)
Dim rng As Range
For Each rng In Sheets("Sheet1").Range(sColRange).Cells 'adjust sheetname and range accordingly
rng.Value = TextOnly(rng.Value)
Next
End Sub
use like this:
Call CleanAll("B2")
Call CleanAll("H2")
Thanks
Edit
The above calls the following
Function TextOnly(strSource As String) As String
Dim i As Integer
Dim strResult As String
For i = 1 To Len(strSource)
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
AlphaNumericOnly = strResult
End Function