Exploring Data in Excel with Conditional Formatting

Conditional formatting is a hidden gem in Excel. It's fairly easy to use, works well, and doesn't get in your way. Here's how we use it to assist in data exploration.

Conditional formatting is found in the Format menu. Most people are probably familiar with using it this way:

Basic conditional formatting

These settings would make any cells with a value greater than 30 have a bright red background. So far, so good.

However, you can do many more powerful things by setting the condition to a formula that is either true or false. For instance, in the dashboard that I created to show the in-cell bar charts, I use a formula like this:

Conditional formatting using the percentile function

This formula compares the value in the cell to the 75th and 25th percentiles of the data in the cells column. If the value is greater than the 75th percentile, use a green font color, if the value is less than the 25th percentile, then use a red font color. The percentiles update automatically with your data.

To get this to work, you need to be mindful of your relative and absolute references. The cell reference on the left hand side of the formula is relative, but the percentile column reference is absolute in rows. This allows you to copy this formula around while maintaining the appropriate ranges. When you start entering formulas for conditional formats, Excel defaults to use absolute references, which doesn't give you the flexibility you need. You'll have to edit the formulas by hand.

Here's another useful case. Sometimes you need to shade alternate rows to make a table more readable. But if someone sorts the table, your shading sorts too. Conditional formatting is an elegant solution and it doesn't even mess with the relative/absolute cell references.

Alternating shading with conditional formatting

The formula =ROW()=EVEN(ROW()) is easy to understand once you know what these obscure functions do. =ROW() returns the row of the current cell. =EVEN(...) rounds some number to an even number. Thus, if ROW() is an even number, the formula is true, and it's false on odd numbered rows.

This last trick is what I use most often. Sometimes you have a very large amount of data that is divided into records with multiple rows per records. Consider something like sales records per customer. You'd like to break this data into chunks—by customer, for instance—as you scan through it.

This conditional format puts a line below each row whenever a particular column value changes.

Displaying a line whenever a value in a column changes

The function is quite simple. If column D has changed, then place a line above the row. However, you do have to be quite careful about relative vs. absolute formatting.

Here is a spreadsheet that contains all the examples discussed above for you to explore.

Excel conditional formatting tips.xls

105 comments | Show all comments only the last 5 are shown


February 26, 2008
Jenny said:

Tim said above: "I am trying to do the same as Felicity Green (comment 97), to make a whole row change color according to the text in a single column on that row. Felicity (or anyone) - have you found a solution to this yet?"

Me too! Has anyone figured out how to do this?


February 26, 2008
Jenny said:

Tim and Felcity: I did get it to work where Excel conditionally formatted a whole row based on the text in one cell.

This is the formula I used:
=$B4="FS"

I chose the entire spreadsheet as my range. It looks like this:
=$B$4:$T$58

Looks like the key is in where to put the dollar signs.

I don't know WHY it works (why do you need to input just the 'b' and not the number), but it is working perfectly.


June 30, 2008
lisa west said:

I am trying to create additional "conditional formats" in Excel 2003 and cannot get the visual basic codes to recognise.

Using:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = True

Dim icolor As Integer

If Not Intersect(Target, Range("A1:AU69")) Is Nothing Then
Select Case Target
Case 75.1 To 90
icolor = 35
Case 90.1 To 100
icolor = 4
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub

If anyone has any bright ideas would be good to hear from you.

Cheers


June 30, 2008
Daniel said:

Can anyone tell me how to combine the last two formatting types above? i.e. Say I want the line formatting as in the last example, but I also want Garciaparra, Thome, and Howard rows all shaded in green, Dunn in white, and back to green for Hafner and Giambi, and so on.

Thanks, Dan


July 3, 2008
John Bundy said:

Lisa West, try doing it like this:

Const WS_RANGE As String = "A1:AU69"
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case Is >= 75.1: .Interior.ColorIndex = 35
Case Is >= 90.1: .Interior.ColorIndex = 4

End Select
End With
End If
ws_exit:
Application.EnableEvents = True

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment





Visualization of Flights

Digg/videos pointed me to this beautiful visualization of dynamic data. The video shows more than 19,000 planes in flight over a 28 hour period. The creator, Aaron Koblin, is one of an emerging group of data-artists (made-up term, made-up theory). Aaron has done much of his work in Processing—an open source language that lets users play with images and data in visual context.

1 comment


August 29, 2006
Francis Norton said:

"Processing" should presumably link to processing.org?

Your name

Email (optional, will not be shared)

Type the word "juice" (required to confuse the spammers)

Your comment


Add a comment