Find cell with text, and change background color...

spacely

Board Regular
Joined
Oct 26, 2007
Messages
248
Hello,

I need a small VBA routine that finds every cell in column A that has the text "Donut" included in it to have its background color changed to another color, like red. A general color would be best like R,G,B values to make it anything.

Thanks a lot!

David
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I need a small VBA routine that finds every cell in column A that has the text "Donut" included in it to have its background color changed to another color, like red. A general color would be best like R,G,B values to make it anything.
Give this macro a try...
Code:
Sub MakeDonutRed()
  Application.ReplaceFormat.Clear
  Application.ReplaceFormat.Interior.Color = RGB(255, 0, 0)
  Columns("A").Replace "*donut*", "", , , False, , False, True
  Application.ReplaceFormat.Clear
End Sub
 
Upvote 0
You could also accomplish this pretty easily with basic conditional formatting:

1. Highlight Column A.
2. From the Home tab, click Conditional Formatting
3. Click "New Rule" > "Format only cells that contains ..."
4. Under "Format only cells with:" enter "Specific text" [in the first drop-down] ... "containing" [in the second drop-down] ... "donut" [type this in]
5. Click "Format..." and select the "Fill" tab. Choose your color.
6. Click "OK" ... "OK"
 
Upvote 0

Forum statistics

Threads
1,226,230
Messages
6,189,768
Members
453,568
Latest member
LaTwiglet85

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top