Question:
Excel 2010 Conditional formatting multiple words in text that contains?
yangsta0057
2012-06-02 12:14:52 UTC
I know how to use "conditional formatting" for single words using "text that contains", but if I have multiple words I want to check for, is there an easier way to do it, or do I have to put each one in separately (which is what I've been doing and it's annoying me).
Three answers:
garbo7441
2012-06-02 14:27:16 UTC
You don't state which cells you are attempting to conditionally format, whether a column or columns, row or rows, or the entire worksheet.



The following example will evaluate the entire worksheet and highlight all cells containing any of the key words. Change the example keywords to your keyword list, adding additional required entries separated by commas.



Copy the following event handler to the clipboard:





Private Sub Worksheet_SelectionChange(ByVal Target As Range)

For Each cell In ActiveSheet.UsedRange

Select Case cell.Text

Case Is = "red", "white", "blue", "yellow"

cell.Interior.ColorIndex = 34

Case Else

cell.Interior.ColorIndex = xlNone

End Select

Next

End Sub



Select the worksheet you wish to conditionally format and right click the sheet tab.



Select 'View Code'.



Paste the event handler into the white editing area to the right.



Close the VBE ane return to the worksheet.



Select any cell.



======================



Now, if you want to format cells that contain additional text in addition to the key words, you can use this event handler instead. Change the keywords to your list, and add additional 'Or' sets for additional keywords.



Private Sub Worksheet_SelectionChange(ByVal Target As Range)

For Each cell In ActiveSheet.UsedRange

If InStr(UCase(cell.Text), "RED") Or InStr(UCase(cell.Text), _

"WHITE") Or InStr(UCase(cell.Text), "BLUE") Or _

InStr(UCase(cell.Text), "YELLOW") Then

cell.Interior.ColorIndex = 34

Else

cell.Interior.ColorIndex = xlNone

End If

Next

End Sub
pelak
2016-12-12 08:58:38 UTC
Excel Conditional Formatting Contains
Nahum
2012-06-03 21:11:48 UTC
Try using a formula like this:

=(COUNTIF(A8,"*" & "one" & "*") + COUNTIF(A8,"*" & "number" & "*")) = 2



Note that the COUNTIF checks the same cell that it is being used for Conditional Formatting.



You can also replace the words with references to cells that have words.



Be warned that this is a "jealous" search: the formula will trigger for phrases like "lonely number". You can try adding spaces to get around this:



=(COUNTIF(A8, "*" & " one " & "*") . . .


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...