jbesclapez
Active Member
- Joined
- Feb 6, 2010
- Messages
- 275
Hello,
I have an error on a line of my VBA where I am trying to find specials characters. This is the line below. It is not working with the "&" and another Chr, and i do not know why
strPatt = Chr(34) & Chr(64)
In the original code it was like this :
Thanks for the help
I have an error on a line of my VBA where I am trying to find specials characters. This is the line below. It is not working with the "&" and another Chr, and i do not know why
strPatt = Chr(34) & Chr(64)
In the original code it was like this :
VBA Code:
'strPatt = "[^a-z,.;:#$%()@" & Chr(34) & "]" 'change pattern as needed
Thanks for the help
VBA Code:
Sub SpecialChar()
Dim strPatt As String
Dim cel As Range
Dim regEx As Object
Application.ScreenUpdating = False
'strPatt = "[^a-z,.;:#$%()@" & Chr(34) & "]" 'change pattern as needed
'strPatt = "/ | ! @ # , ; ^ * + - = \ ? < > [ ] { } ’ " & Chr(132) & Chr(34) & Chr(147) & Chr(148) 'change pattern as needed
'strPatt = "/|!@#,;^*+-=\?<>[]{}’"
'strPatt = "[/|!@#,;^*+-\,.;:#$%()@" & Chr(63) & "]" 'change pattern as needed
strPatt = Chr(34) & Chr(64) 'change pattern as needed
'strPatt = Chr(47) & Chr(124) & Chr(33) & Chr(64) & Chr(35) & Chr(44) & Chr(59) & Chr(94) & Chr(42) & Chr(43) & Chr(45) & Chr(61) & Chr(92) & Chr(63) & Chr(60) & Chr(62) & Chr(34) & Chr(91) & Chr(93) & Chr(123) & Chr(125) & Chr(146)
'/|!@#,;^*+-=\?< > "[]{}’
Set regEx = CreateObject("VBScript.RegExp")
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = strPatt
End With
For Each cel In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).row).Cells 'change column as needed
If regEx.Test(cel.Text) Then
cel.Interior.Color = vbRed
End If
Next cel
Application.ScreenUpdating = True
End Sub