Excel Macro how to check if cells contains special character

dehachopper

New Member
Joined
Aug 27, 2014
Messages
4
I want to make a macro that can check if a cells is contains special character like '%^&' but also alt+enter, here is my macro:
Sub CHECK_Click()
Dim regEx As Object
Dim formulaColorWrong As Long
Dim formulaColorRight As Long

formulaColorRight = RGB(Red:=0, Green:=0, Blue:=0)
formulaColorWrong = RGB(Red:=255, Green:=0, Blue:=0)
Set regEx = CreateObject("VBScript.RegExp")
regEx.Global = True
regEx.Pattern = "[!0-9A-Za-z.,@_-]"
Sheets("CheckSheet").Activate
For Each objCell In ActiveSheet.UsedRange.Cells
If regEx.Test(objCell.Value) Then
objCell.Font.Color = formulaColorRight
Else
objCell.Font.Color = formulaColorWrong
End If
Next
End Sub

it works properly but can't catch alt+enter expression.
could someone help me out?:eek::eek:
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Check this:

Code:
Sub CHECK_Click()
Dim regEx As Object
Dim formulaColorWrong As Long
Dim formulaColorRight As Long

formulaColorRight = RGB(Red:=0, Green:=0, Blue:=0)
formulaColorWrong = RGB(Red:=255, Green:=0, Blue:=0)
Set regEx = CreateObject("VBScript.RegExp")
regEx.Global = True
regEx.Pattern = "[!0-9A-Za-z.,@_-]"
Sheets("CheckSheet").Activate
For Each objCell In ActiveSheet.UsedRange.Cells
If regEx.Test(objCell.Value) And InStr(1, objCell.Value, Chr(10)) = 0 Then
objCell.Font.Color = formulaColorRight
Else
objCell.Font.Color = formulaColorWrong
End If
Next
End Sub
 
Upvote 0
Check this:

Code:
Sub CHECK_Click()
Dim regEx As Object
Dim formulaColorWrong As Long
Dim formulaColorRight As Long

formulaColorRight = RGB(Red:=0, Green:=0, Blue:=0)
formulaColorWrong = RGB(Red:=255, Green:=0, Blue:=0)
Set regEx = CreateObject("VBScript.RegExp")
regEx.Global = True
regEx.Pattern = "[!0-9A-Za-z.,@_-]"
Sheets("CheckSheet").Activate
For Each objCell In ActiveSheet.UsedRange.Cells
If regEx.Test(objCell.Value) And InStr(1, objCell.Value, Chr(10)) = 0 Then
objCell.Font.Color = formulaColorRight
Else
objCell.Font.Color = formulaColorWrong
End If
Next
End Sub

Thank you.. it's works.. :)
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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