Solved

Find string and color cell if found

Posted on 2013-01-19
3
672 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:
teylyn earned 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now