I am trying to use vba to read client feedback and reference it to a set of keywords mapped to categories. However the problem I am having is that on occasion, clients use special characters such as “ -^<* ‘ in their comments and this is breaking my code as soon as it hit such a string. How can I make my code ignore these special characters and keep moving down the rows to search for criteria? Thanks in advance
-
Use an encoder as used in a url encoding can solve your problem. w3schools.com/tags/ref_urlencode.aspRuchan– Ruchan2019-03-18 13:10:24 +00:00Commented Mar 18, 2019 at 13:10
-
1How do you "search for criteria"? Do you compare the value of each cell individually by string comparison?Asger– Asger2019-03-18 13:15:51 +00:00Commented Mar 18, 2019 at 13:15
-
1It is easy to do if you update your question with a specific list of the characters you want to ignore.Gary's Student– Gary's Student2019-03-18 13:17:40 +00:00Commented Mar 18, 2019 at 13:17
-
1This is one scenario where using RegEx seems to be fit, so you can filter only the characters you want, rather than trying to remove each possible new code breaking char. replace-text-using-regex-in-excel-vbaFAB– FAB2019-03-18 13:17:43 +00:00Commented Mar 18, 2019 at 13:17
Add a comment
|
1 Answer
First place the data to be "cleaned-up" in column A, then run:
Sub Kleanup()
Dim A As Range, aa As Range, L As Long, i As Long
Dim CH As String, temp As String
Set A = Range("A:A")
For Each aa In Intersect(A, ActiveSheet.UsedRange)
If aa <> "" Then
L = Len(aa)
temp = ""
For i = 1 To L
CH = Mid(aa, i, 1)
If CH Like "[A-Za-z0-9]" Then
temp = temp & CH
End If
Next i
aa.Value = temp
End If
Next aa
End Sub
It will remove all characters except 0 through 9 and upper case letters and lower case letters.