Find string and color cell if found

Posted on 2013-01-19
Last Modified: 2013-01-19

I have the following code which looks for cells in column B and colors any cell blue that contains a certain string. This works ok but now I need to color any cell that has WATERBALL in it, even if WATERBALL is only a partial match (like "Red  WATERBALL", or "Blue Waterball"). This code only works for an exact match including case.

lRow = Range("B" & Rows.Count).End(xlUp).Row
Set MR = Range("B2:B" & lRow)
For Each cell In MR
If cell.Value = "WATERBALL" Then cell.Interior.ColorIndex = 28

Further, I need a second string "Float" found and colored some other color (purple?)
This works but again, only for an exact match.

lRow = Range("B" & Rows.Count).End(xlUp).Row
Set MR = Range("B2:B" & lRow)
For Each cell In MR
If cell.Value = "WATERBALL" Then cell.Interior.ColorIndex = 28
If cell.Value = "Float" Then cell.Interior.ColorIndex = 39

Thanks in advance,

Question by:swjtx99
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 38797647
Hmm....Googling led me to this which didn't work at all....

Sub Find_String()

lRow = Range("B" & Rows.Count).End(xlUp).Row
Set MR = Range("B2:B" & lRow)
For Each cell In MR
If UCase(ActiveCell.Value) Like "WATERBALL" Then cell.Interior.ColorIndex = 28
If UCase(ActiveCell.Value) Like "Float" Then cell.Interior.ColorIndex = 39

End Sub
LVL 50

Accepted Solution

Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 500 total points
ID: 38797651


Option Explicit

Sub test()

Dim lrow As Long
Dim MR As Range
Dim cel As Range

lrow = Range("B" & Rows.Count).End(xlUp).Row
Set MR = Range("B2:B" & lrow)
For Each cel In MR
If InStr(UCase(cel.Value), "FLOAT") Then cel.Interior.ColorIndex = 39
If InStr(UCase(cel.Value), "WATERBALL") Then cel.Interior.ColorIndex = 28


End Sub

Open in new window

cheers, teylyn

Author Closing Comment

ID: 38797666

Thanks for your help,


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question