Error on my VBA for find special characters

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 :
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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Got it after my break. Sorry
The code below will work. I forgot teh brackets.
strPatt = "[" & Chr(64) & Chr(63) & "]" 'change pattern as needed"
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top