Conditional Formatting: Adding Customized Icon Sets to Excel 2007

Switch View :
ScriptFree
Conditional Formatting: Adding Customized Icon Sets to Excel 2007

Summary: Icon sets give you an opportunity to create visual effects in your data to see how the value of a cell compares with other cells. Learn how to implement and manipulate icon sets through the user interface and programmatically. (5 printed pages)

Frank Rice, Microsoft Corporation

April 2007

Applies to:   2007 Microsoft Office Suites, Microsoft Office Excel 2007

Contents

Overview

This column continues my discussion on conditional formatting in Microsoft Office Excel 2007 by introducing another visualization you can apply to your data to give it a little more punch - icon sets. As the name implies, this feature allows you to put icons in cells based on the values of the cell. Icon sets are similar in some ways to data bars and color scales; so much of the information that I covered in previous Office Talk columns applies to icon sets as well. For more information on these features, see More information about Conditional Formatting in Excel 2007. The primary differences are that:

  • You can specify a number of categories for the data (between three and five categories).

  • You can choose a set of icons that you want to appear in the cells for each category.

  • You can have Excel determine the categorization of each cell relative to all cells in the selected range so that it can draw the appropriate icon in the each of the cells.

This is very effective when you are trying to annotate and present data in a way that is quickly readable and comprehensible.

A Large Selection of Icon Choices

Excel 2007 offers several choices of icon sets. You can choose the icons that are most appropriate for the data you are using. Figure 1 shows the gallery of icons as well as the user interface (UI) to get to the icons. The Condition Formatting option is available on the Home tab.



Figure 1. Excel 2007 offers many sets of conditional formatting icons

Sets of conditional formatting icons

Let's look at some examples. Figure 2 is an example of red-yellow-green icons in a range of data:



Figure 2. Red-Yellow-Green geometric icons applied to a range of data

Geometric icons applied to a range of data

Figure 3 is an example of a range of data with colored arrows in different directions, relative to the middle values in the range. Arrows tend to indicate trends:



Figure 3. Colored arrows indicate direction relative to mid-range values

Colored arrows indicate direction

The next example shows five different categories grouped using a circle that ranges from empty through filled (similar to the phases of the moon or a pie chart):



Figure 4. Icons display a pie chart-like indicator of percentage of fill

Pie chart icons indicate percentage of fill

Like data bars and color scales, you can set the value for each of the different categories in an icon set using numbers, percent, percentiles, and formulas. By default, Excel uses percentiles. For example, in the three-icon case, Excel sets 33% and 67% as the break between the three sets of icons.

What You Can and Can Not Do with Icon Sets

Here are some answers to questions you may have about icon sets:

  • Icon sets come in three sizes, so as you increase or decrease the font size, the icon become larger or smaller, as appropriate.

  • You cannot add your own icons in this release of Excel. However, as you have seen, there are a large number of icons to choose from so this should not be an issue.

  • It is possible to hide the value of the cell and just draw the icon when you apply a conditional formatting rule for icon sets. This enables you to build all sorts of interesting "dashboards" in Excel 2007.

  • For people familiar with Microsoft SQL Server 2005 Analysis Services Key Performance Indicators (KPI), data imported into Excel is synched up with the graphics, so if you use Analysis Services KPIs in Excel 2007, when you apply conditional formatting rules, the correct icons are put into the cells automatically.

  • You can overwrite default behavior of the icon by using formulas. For example, for a growing portfolio, a negative net income might not be a true "red" as long as it is more than that outlined in a plan.

Using Icon Sets Programmatically

You can also specify icon sets and icon set criteria programmatically. Excel 2007 provides an IconSets collection containing the set of IconSet objects, an IconSet object that represents a single set of icons, and an IconSetCondition object that represents an icon set conditional formatting rule. There is also an IconCriteria collection, which represents the set of criteria for an icon set conditional formatting rule. Using the methods and properties associated with these objects provides a considerable amount of flexibility in setting conditions and criteria to make your data more meaningful to the user.

The following code example creates a range of numbers and then applies an icon set conditional formatting rule to that range. A 5-arrow icon set is chosen as the type of icon set. Finally, the threshold type is modified from percentile to a hard-coded number.

Bb407306.note(en-us,office.11).gifNote:

An easy way to implement this code sample is to add a button to the Ribbon in Excel 2007. You can see the steps to do this in my previous Office Talk columns on conditional formatting.

Visual Basic
Sub CreateIconSetCF()
Dim cfIconSet As IconSetCondition

' Fill cells from C1 to C12 with sample data.
With ActiveSheet
   .Range("C1") = 55
   .Range("C2") = 92
   .Range("C3") = 88
   .Range("C4") = 77
   .Range("C5") = 66
   .Range("C6") = 93
   .Range("C7") = 76
   .Range("C8") = 80
   .Range("C9") = 79
   .Range("C10") = 83
   .Range("C11") = 66
   .Range("C12") = 74
End With

Range("C1:C12").Select

' Create an icon set conditional format for the created sample data range.
Set cfIconSet = Selection.FormatConditions.AddIconSetCondition

' Change the icon set to a 5-arrow icon set.
cfIconSet.IconSet = ActiveWorkbook.IconSets(xl5Arrows)

' The IconCriterion collection contains all the icon criteria. By indexing into
' the collection, you can modify each criteria. The following sections set
' the criteria for each of the arrows in the set.
With cfIconSet.IconCriteria(1)
   .Type = xlConditionValueNumber
   .Value = 0
   ' XlFormatConditionOperator enumeration that specifies "greater than 
   ' or equal to."
   .Operator = 7
End With
With cfIconSet.IconCriteria(2)
   .Type = xlConditionValueNumber
   .Value = 60
   .Operator = 7
End With
With cfIconSet.IconCriteria(3)
   .Type = xlConditionValueNumber
   .Value = 70
   .Operator = 7
End With
With cfIconSet.IconCriteria(4)
   .Type = xlConditionValueNumber
   .Value = 80
   .Operator = 7
End With
With cfIconSet.IconCriteria(5)
   .Type = xlConditionValueNumber
   .Value = 90
   .Operator = 7
End With

End Sub

Running this procedure results in the display shown in Figure 5.



Figure 5. The result of applying an icon set conditional rules to a range of data

Applying icon set conditional rules to data

To Summarize

Icon sets make it very easy to see at a glance how data values relate to each other as well as trends in your data. You have also seen how easy it is to add icon sets to your data by using the Excel 2007 conditional formatting UI as well as by adding them programmatically. Changing the types of icon sets and their thresholds is also very easy.

In future columns, I discuss other aspects of the new conditional formatting enhancements in Excel 2007, including the flexibility that is added to conditional formatting rules.

More information about Conditional Formatting in Excel 2007

Community Content

IDelevan
Conditional Formatting Not Behaving as it Sould
What can I do to make Conditional Formatting look at specific values and base the Icon set color off those values, vesus, lookong at other rows and giving the worng colors even when the rules says for example "> than a certain % it shuold be such and such color" etc.,?   Wish I could send you a graphic/snip.

bek050381
sideways arrow icon
I try conditional formatting icon sets, but it gives me up-arrow for cells that should be sideways-arrow.

gth-au
Pls add support for user-contributed iconsets (bundle with XLSX file)
Definitely need the option to add a set of user's own set of images as an additional iconset.  Failing that, can MS please add some "gauge" like icons as system-provided iconsets (Excel 2010 SP1 ?)

Any user-contributed iconsets would be added to the local install of Excel 2007, but more importantly to be saved within any spreadsheet that uses them so all recipients can view them correctly.  This would bloating filesize (moreso if the user has no idea about typical icon image sizes), and probably cause security folks to whine about images being 'hidden' inside XLSX files...

SailorShim
Adjacent cells an option?
Is it possible to have an Icon Set Conditional Formatting to compare adjacent cells???  I am looking to compare column A with Column B and wish to know whether it is up or down from that column.  There are not number or percentage criteria to be set, just if it is above, the same, or below the column next to it.

Thanks!

Ola1983
Exactly!
It would be very lovely if some addressed this issue.
I would like to demonstrate Risk assesment with colored icons, putting red circle icon next to High Risk, yellow for Medium Risk and green for Low Risk. I might add common shapes to a cell, but with modyfing the cells parameters all the time, such solution does not seem reasonable.
I don't seem to find other option in Excel to demonstrate it graphically. If not only '>=' but other conditioners as '=' or' equals to' could be used, it would be a perfect solution to this problem.
Can anybody advice me on that? Would be very grateful.

Mr. Mike
Nice Start... but please add an = to condition.

Thank you for the new icon sets, but I'd like a way to concatenate icon sets. 
For example I'm using the 4 Stop Lights Green (On Track), Yellow, Red, Black based upon a status field. I'd also like to use the Thee Symbols set for the Green Checkmark (Complete) on a project dashboard.
I am not a programmer and there may be another way but it seems to me that if you modified the conditional formatting settings for number and simply provided a = only option along with the existing > & >= options then you could apply any mix of the icon sets based on a simple formulas like: if cell = complete, 1 started = 2, etc ....
With the current conditions statements set to Greater Than x or Less Than y limits the number of conditions that can be evaluated to the number of icons in that set.
Please remove this limitation.  <or explain how to workaround this>

Thank you!

Cry Havoc
Color Blind!
There are very limited icon sets suitable for the color blind. I'd like to use the red, yellow, green "traffic lights", but can only do so if there is a graphical difference too. 
Note: approximate 15% of the male population of Europe & North America has some form of color blindness. 

sixequalszero
How arrogant can you be?
"You cannot add your own icons in this release of Excel. However, as you have seen, there are a large number of icons to choose from so this should not be an issue."

It is not hard to let us use custom icons. The "large number of icons" is minimal and neglects the prominent five star classification system.

Thomas Lee
conditional formatting in Excel 2008 for Mac
Hi

any idea why this great expansion to more than 3 conditions is not implemented in Excel for Mac (2008)?

or is there an add on that I forgot to install?

cheers

Mark

[tfl - 10 12 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&


Thomas Lee
red arrow pointing up

Hello

I would like to know if there is a possiblity to change arrow color

I mean I would like to display an arrow pointing up but red and not green, an opposite green arrow point down.

I would liket o display amount of error per week and in case that this number is decrease it's a good sign

Thanks
Franck


[tfl - 10 12 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&

Multi System User
Re: conditional formatting in Excel 2008 for Mac
I think it is pretty apparent that Microsoft has disabled some key features in the Mac version as a way of penalizing customers for not running their OS. Office also runs much slower in Mac, even though every other multi-platform application I've personally used (Adobe, especially) runs faster. Running Office on Mac rather than Windows equates to being treated like a second-hand citizen. Every single thing about the Mac version is worse. Even the Mactopia support site is more difficult to use and has less information. Luckily, the alternatives are all getting much, much better.

Mark N2
Icon Sets fall short of telling the basic story.

The Icon sets are limited. No icon set allows you to show decreasing value as positive. The icon set needs to be provided in the reverse color combination (green arrows down, red arrows up).

Why? A green arrow pointing down shows improved employee attrition, improved gas mileage, reduced global warming. A red arrow pointing up shows negative aspects of high blood pressure, higher interest rates, higher flood waters.

This is a weakness that need to be addressed.