I need a macro to mark all cases where I have a "letter-comma-letter" in a text

Gabriel Rotar

New Member
Joined
Mar 5, 2021
Messages
7
Office Version
  1. 2013
Platform
  1. Windows
Hello,

I created a macro to detect text errors, but I have a case where I need to identify the case where a comma is placed between 2 words without a space behind, so the macro should mark all the cells where the text contains situations like "r,p" or "a,N" but not with spaces or numbers included like "2,5" or "a, M".
Below is my search function, but the string format is my problem.
Thank you in advance! Have a good day!

Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlTextString, String:="[a-z],[a-z]", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = vbGreen
End With
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
if you want to correct the problem by inserting a space, you can do a replace:
VBA Code:
MyString = Replace(MyString, ",", ", ")
MyString = Replace(MyString, ",  ", ", ")

then you just need to exclude the 2,5 case which is at least a start
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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