Looping with "contains" a certain text string

BillTony

Board Regular
Joined
May 3, 2017
Messages
70
Hi there - I'm kinda new to "Loops."

The code snippet below shows that I'm running a loop through column CH and changing the cell color of values in column A based on the results of that loop.

The "key" to the loop is the word "ERROR."

However, what I NEED to do is to have some flexibility there - I need to be able to key the loop on a word contained within a text string.

For instance, right now I need to "focus" on the word "Record."

There will be several different text strings - about half may contain "Record" (Record not found, Record incorrect, No record created, etc.)

So I need to search all text strings and just pull out those containing "Record"/"record."

Thanks in advance!

Code:
For i = 3 To Last_Row_ColCH
'So, if there is an "ERROR" in a Cell in Column CH - the CORRESPONDING Cell in Column A will CHANGE COLOR.
        If Range("CH" & i).Value = "ERROR" Then Range("A" & i).Interior.ColorIndex = 3
'Continues the LOOP - this will run to the LAST ROW in Column CH CONTAINING a VALUE.
    Next i
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Does this need to be VBA, you could do it very easily with conditional formatting
 
Upvote 0
Ok, try
Code:
   If InStr(1, Range("CH" & i), "Record", vbTextCompare) > 0 Then Range("A" & i).Interior.ColorIndex = 3
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,386
Members
448,891
Latest member
tpierce

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