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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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