Select Cells that contain specific text vba

Vivelake

New Member
Joined
Feb 17, 2022
Messages
10
Hi,

For work we often get a spreadsheet that for my use I need to filter and highlight certain columns.
For example one column has some cells that contain the word yes. I need to highlight every cell that says yes and also highlight another cell in that row.
So if row 5 has the word yes in column B both B5 and another cell in the row need to be highlighted (i.e. E5)
The document has a different amount of entries every week but usually around 1500 row.
I have tried a couple of different ways but I'm new to VBA.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
welcome to the forum, try this code:
VBA Code:
Sub testr()
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
inarr = Range(Cells(1, 2), Cells(lastrow, 2))
Range(Cells(1, 2), Cells(lastrow, 2)).Interior.Color = xlNone 'remove existing colors
Range(Cells(1, 5), Cells(lastrow, 5)).Interior.Color = xlNone
For i = 1 To lastrow
 If inarr(i, 1) = "yes" Then
    Range(Cells(i, 2), Cells(i, 2)).Interior.Color = vbRed
    Range(Cells(i, 5), Cells(i, 5)).Interior.Color = vbRed
 End If
 Next i
 End Sub
 
Upvote 0
Welcome to the Board!

You should be able to just use Conditional Formatting to do this.
Just select columns B and E, and then use this Conditional Formatting formula:
Excel Formula:
=$B1="Yes"
and then choose your desired highlighting color.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,086
Messages
6,123,035
Members
449,092
Latest member
ikke

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