Add color to cell when a cell contains a set of words.

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
743
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Greetings I am hope to adjust the macro so that it will highlight the row between Columns A:E. I want this particular Maco to do it's job any time "CUST & AG REQ" occurs anywhere in Column E. "CUST & AG REQ" can appear anywhere in Column E, and I don't want to list all the variances that it can occure.

VBA Code:
Sub Local_BACKGROUND()
    Sheets("72 Hr").Select
    endrow = Range("E" & Rows.Count).End(xlUp).Row
    
    For Each cell In Range("E3:E" & endrow)
        Select Case cell.Value
            Case "CUST & AG REQ"
                Range(Cells(cell.Row, "A"), Cells(cell.Row, "E")).Interior.ColorIndex = 45
            
        End Select
    Next cell
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I would do it like this:
VBA Code:
Sub Local_BACKGROUND()

    Dim endrow As Long
    Dim cell As Range

    Sheets("72 Hr").Select
    endrow = Range("E" & Rows.Count).End(xlUp).Row
   
    For Each cell In Range("E3:E" & endrow)
        If InStr(cell, "CUST & AG REQ") > 0 Then
            Range(Cells(cell.Row, "A"), Cells(cell.Row, "E")).Interior.ColorIndex = 45
        End If
    Next cell
   
End Sub

Note that this can also be done pretty easily just using Conditional Formatting (no VBA required).
 
Upvote 0
Solution
I would do it like this:
VBA Code:
Sub Local_BACKGROUND()

    Dim endrow As Long
    Dim cell As Range

    Sheets("72 Hr").Select
    endrow = Range("E" & Rows.Count).End(xlUp).Row
 
    For Each cell In Range("E3:E" & endrow)
        If InStr(cell, "CUST & AG REQ") > 0 Then
            Range(Cells(cell.Row, "A"), Cells(cell.Row, "E")).Interior.ColorIndex = 45
        End If
    Next cell
 
End Sub

Note that this can also be done pretty easily just using Conditional Formatting (no VBA required).
Thank you, I didn't think it worked at first but forgot to plug in on my Run all Macro. It's perfect as of righ now.
 
Upvote 0
I would do it like this:
VBA Code:
Sub Local_BACKGROUND()

    Dim endrow As Long
    Dim cell As Range

    Sheets("72 Hr").Select
    endrow = Range("E" & Rows.Count).End(xlUp).Row
  
    For Each cell In Range("E3:E" & endrow)
        If InStr(cell, "CUST & AG REQ") > 0 Then
            Range(Cells(cell.Row, "A"), Cells(cell.Row, "E")).Interior.ColorIndex = 45
        End If
    Next cell
  
End Sub

Note that this can also be done pretty easily just using Conditional Formatting (no VBA required).
I thought about that, but I have a macro that clears everything out including all conditional formats.
 
Upvote 0
I thought about that, but I have a macro that clears everything out including all conditional formats.
You are welcome.

Yes, I figured it might be something like that, but just wanted to mention it, just in case.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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