Highlight Cells
- The following assumes that the
A
column contains the criteria (Run
) and the B
column is formatted. Adjust this to fit your needs.
Excel
In e.g. cell B2
use the conditional formatting rule (Use a formula to determine which cells to format
)...
=A2="Run"
... and copy down.
VBA
- Adjust the values in the constants section and the worksheet (Something like
Set ws = Thisworkbook.Worksheets("Sheet1")
is preferred (safer).).
Option Explicit
Sub HighlightCells()
Const sCol As String = "A"
Const sFirst As Long = 2
Const sCriteria As String = "Run"
Const dCol As String = "B"
Const dColor As Long = vbGreen
Dim ws As Worksheet: Set ws = ActiveSheet
Dim sLast As Long: sLast = ws.Cells(ws.Rows.Count, sCol).End(xlUp).Row
If sLast < sFirst Then Exit Sub
Dim r As Long
Dim sString As String
For r = sFirst To sLast
sString = CStr(ws.Cells(r, sCol).Value)
If sString = sCriteria Then
ws.Cells(r, dCol).Interior.Color = dColor
End If
Next r
End Sub
Conditional Formatting in VBA
(a third option)