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
Solved

Find string and color cell if found

Posted on 2013-01-19
3
685 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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 Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

792 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