Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find string and color cell if found

Posted on 2013-01-19
3
Medium Priority
?
709 Views
Last Modified: 2013-01-19
Hi,

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
    Next


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
    Next

Thanks in advance,

swjtx99
0
Comment
Question by:swjtx99
  • 2
3 Comments
 

Author Comment

by:swjtx99
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
    Next

End Sub
0
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 2000 total points
ID: 38797651
Hello,

maybe

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

    Next

End Sub

Open in new window


cheers, teylyn
0
 

Author Closing Comment

by:swjtx99
ID: 38797666
Works!

Thanks for your help,

swjtx99
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

927 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