Jon Gallant's Blog

dev lead @ microsoft

How To Highlight Rows Based on a Cell Value in Excel

How To Highlight Rows Based on a Cell Value in Excel

  • Comments 19

Here’s how to highlight rows based on a cell value in Excel 2007 and Excel 2010.  Reference this page for previous versions of Excel

 

1) Select the table you want to apply the custom formatting to

ExcelRowHighlight_Table

2) Go to the Conditional Formatting ribbon option and select “New Rule”

ExcelRowHighlight_ConditionalFormatting

3) Format Setting

Select “Use a formula to determine which cells to format” in the “Select a Rule Type” box

Enter the INDIRECT function into the Rule Description Text Box

        INDIRECT method syntax:  =INDIRECT(“[COLUMN LETTER]”&ROW())=[VALUE]

Select a Format to Apply to the matching rows

Click OK

ExcelRowHighlight_EditFormattingRule

4) View the table and adjust the INDIRECT settings as required.

ExcelRowHighlight_TableFormatted

HTH,

Jon

Leave a Comment
  • Please add 6 and 2 and type the answer here:
  • Post
  • Great tip!!!

    Thank you much!

    Have been looking for some time before I found this - very useful extension of standard conditional formatting highlight rules.

  • thank you very much! keep up the great tips.

  • Thanks a ton! Found this after a bit of searching - you are a lifesaver

  • Thanks a lot! Just what I wanted!

  • Perfect! I've been looking for this

  • Thanks a lot

  • Iam glad i found this page, have been looking for this solution for quite some time.

    Have a question though !!

    If i want to conditional format the row based on the value of a cell , say for ex if cell value in clumn 'S' is 'A' then the row font colour needs to be green , or if the cell value is "B" the row font colour needs to be red , if the cell value is "C" a different font colour for the row. How do i acheive this ?  is there a way to use OR() in the same conditional formatting rule or do i  need to create a new rule for every value that iam formatting against . ( like 1 rule for "A" another for "B" and another for "C") ??

  • @satya - I think you need to create a rule for every condition or use script.

  • @satya - Here's an example of why I love Microsoft.  I forwarded your question to the internal Excel experts and got this response from Randy.....send me your email address if you want me to forward the Excel doc to you.  Contact me via the blog contact page.

    It can be done with code if he has lots of conditions.

    I made a simple macro that selects 100 cells (A1:A100) and makes 100 Format Conditions, using Random Colors. (First Button)

    The customer could make an Array of  (Cell address, Conditional Values, Interior Color, and Font Color ), and run then in a macro, without having to do each manually. (Second button)

    I tested it in XL2010 with up to 1000 cells and 1000 custom formats.

    Option Explicit

    Option Base 1

    Sub TestArray()

    Dim FormatArray()

    FormatArray = Sheet2.Range(Cells(2, 8), Cells(6, 10)).Value

    Debug.Print FormatArray(5, 2)

    End Sub

    Option Explicit

    Sub ConditionalFormattingMacro()

    Dim celFMT As FormatCondition

    Dim x

    Dim vRed, vGreen, vBlue

    Application.ScreenUpdating = False

    ActiveSheet.Range("A1:A100").Select

    Selection.Clear

    For x = 1 To 100

    Randomize

    vRed = Int(Rnd() * 255)

    vGreen = Int(Rnd() * 255)

    vBlue = Int(Rnd() * 255)

    Set celFMT = Selection.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=" & x)

    celFMT.Interior.Color = RGB(vRed, vGreen, vBlue)

    Randomize

    vRed = Int(Rnd() * 255)

    vGreen = Int(Rnd() * 255)

    vBlue = Int(Rnd() * 255)

    celFMT.Font.Color = RGB(vRed, vGreen, vBlue)

    Next

    [A1].Select

    End Sub

    Sub ConditionFormatting_CustomArray()

    Application.ScreenUpdating = False

    Dim celFMT As FormatCondition

    Dim x

    Dim vRed, vGreen, vBlue

    Dim FormatArray()

    Sheet2.Select

    FormatArray = Sheet2.Range(Cells(2, 8), Cells(6, 10)).Value

    Sheet1.Select

    ActiveSheet.Range("A1:A100").Select

    Selection.Clear

    'Setting 5 conditions for the format range.

    For x = 1 To 5

    Set celFMT = Selection.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=" & FormatArray(x, 1))

    celFMT.Interior.ColorIndex = FormatArray(x, 2)

    Randomize

    vRed = Int(Rnd() * 255)

    vGreen = Int(Rnd() * 255)

    vBlue = Int(Rnd() * 255)

    celFMT.Font.ColorIndex = FormatArray(x, 3)

    Next

    End Sub

  • Your solution really helped. Thanks Jon

  • How Conditional formating if Value is some text

    E.g. = If i want to highlight a row with 4 different colors, that contains 4 specific text (Jon / Jerry / Bob / Shally)

    Word "Jon" Row should highlight Red

    Word "Jerry" Row should highlight Yellow

    Word "Bob" Row should highlight Green

    and so on...

  • Thank you for this. Very easy to understand.

  • This does not work, even using the exact same values in your example. Did an update break this?

  • Great tip--thank you!!!

  • Thanks! Very efficient...

Page 1 of 2 (19 items) 12
Search