Excel Dashboard Controls – Multiple Value Filters

How to create a multiple value filter control including a “select all / none” option with Microsoft Excel

Multiple Value Filter Control

If you ever built interactive Microsoft Excel dashboards, I am betting the ranch that there was at least one with some kind of interactive filtering features. For selecting one out of several categories you probably used a drop down list (i.e. a combo box). If you need a multi filter control (i.e. selecting several categories) a multi select list box or several check boxes are the way to go. We had that before: In one of the first articles on this blog I already showed different techniques of how to implement a multi-select control feature on Microsoft Excel dashboards (Approach with Caution).

So far, so good. However, what I didn’t discuss in that article is one obvious requirement you may have for a multiple value filter control on a dashboard: an option to let the user easily select all or none categories with one single mouse click. Especially helpful if you are having a lot of categories.

Today’s post tries to fill this gap: this article shows several options of how to implement a multiple value filter control based on check boxes, including an additional check box to easily select and deselect all categories. As always, the post provides all Excel workbooks for free download. 

The Challenge

Well, I guess I already sufficiently described the challenge in the introduction to this post: Create a multiple value filter control including an easy-to-use option for selecting all or none categories with one single mouse click. I.e. produce something like this:

Multiple Value Filter Control - click to enlarge

A painfully obvious requirement, isn’t it? However, there is no built-in functionality of Microsoft Excel that allows doing this with ease. Unlike with Tableau Software. But I am running off topic.

Here are 3 different ways of how to produce a multiple value filter list including a select/deselect all check box using Microsoft Excel:

Approach 1 – Form Control Check Boxes

This is probably the easiest way of doing this using form control check boxes. Only 4 simple steps necessary:

  1. Insert a form control check box for each category and link them to a continuous range somewhere in your workbook. Add another check box called “All” and link it to a cell too.
  2. Define names for the ranges like “myActualFilter” for the range with the target cells of the category check boxes and “myCheckBoxAll” for the “All” check box.
  3. Add the following VBA to a new module in the VBE:

    Option Explicit

    Sub UpdateCheckBoxAll()
        On Error Resume Next
        Range("myActualFilter").Value = Range("myCheckBoxAll").Value
    End Sub

    Sub UpdateSingleCheckboxes()
        On Error Resume Next
        Range("myCheckBoxAll").Value = _
                  Application.WorksheetFunction.And(Range("myActualFilter").Value)
    End Sub

    The code is pretty straight forward. The sub UpdateCheckBoxAll assigns the actual value of the “All” check box to the target range of all category check boxes. This way all other check boxes are selected or deselected. The sub UpdateSingleCheckbox uses the worksheet function AND to set the value of the “All” check box. If all values of all category check boxes are True, the “All” check box is set to True. Otherwise it is set to False.

  4. Finally assign the sub UpdateCheckBoxAll to the “Select/Deselect All” check box and the sub UpdateSingleCheckboxes to all other check boxes.

That’s it.

Here is an example workbook including this technique:

Download Multiple Value Filter using Form Checkboxes (Microsoft Excel 2003, 86.5K)

Approach 2 – ActiveX Controls and the Triple State Property

Instead of form controls, you can also use ActiveX controls. ActiveX controls are the sophisticated siblings of form controls. They are more complex to use, but they offer much more flexibility than form controls: for instance, you can change the appearance (like colors) or the font. Furthermore you have more options to define their behavior. One of the behavior properties of an ActiveX check box is the so called TripleState.  If you set the TripleState property to True, like this

Triple State Property - click to enlarge

a check box has three different values: True, False and Null. If it is Null, the check in the check box will be grey instead of black. A nifty additional feature and visualization, which can be used for indicating that some but not all categories are checked.

Unlike form controls, you can not directly assign a macro to ActiveX controls. Instead, Excel provides event procedures to be triggered with certain actions of the ActiveX controls.

Here are the main steps:

  1. Insert the ActiveX check boxes (one for each category and an additional one called “All”)
  2. Define the target cell in the property LinkedCell (right click on the ActiveX check box, select properties and defined the target cell)
  3. Set the TripleState property to True (see screenshot above)
  4. Insert the following code into a new module in the VBE:

    Option Explicit

    Sub Update_CheckBoxAll()
        On Error Resume Next
        With ActiveSheet
            If .CheckBox1.Value = True Then
                .CheckBox2.Value = True
                .CheckBox3.Value = True
                .CheckBox4.Value = True
                .CheckBox5.Value = True
                .CheckBox6.Value = True
            ElseIf .CheckBox1.Value = False Then
                .CheckBox2.Value = False
                .CheckBox3.Value = False
                .CheckBox4.Value = False
                .CheckBox5.Value = False
                .CheckBox6.Value = False
            End If
        End With
    End Sub

    Sub Update_SingleCheckBox()
        On Error Resume Next
        If Application.WorksheetFunction.And(Range("myActualFilter").Value) Then
            ActiveSheet.CheckBox1.Value = True
        ElseIf Not _
            (Application.WorksheetFunction.Or(Range("myActualFilter").Value)) Then
            ActiveSheet.CheckBox1.Value = False
        Else
            ActiveSheet.CheckBox1.Value = Null
        End If
    End Sub

    The sub Update_CheckBoxAll assigns the value of the “All” check box to all other check boxes. If the user clicks on “All”, all categories are selected. If he clicks again, all are deselected.

    The sub Update_SingleCheckBox is an enhancement of the sub used in the form controls approach (see above). If all categories are checked, the “All” check box is set to True, if all categories are unchecked (the ElseIf part), the “All” check box is set to False, otherwise (the Else part) it is set to Null, i.e. the “All” check box will show a grey check.

  5. Finally, add the following code to the VBE of your dashboard worksheet (i.e. the worksheet with the check boxes):

    Option Explicit

    Private Sub CheckBox1_Click()
        Call Update_CheckBoxAll
    End Sub

    Private Sub CheckBox2_Click()
        Call Update_SingleCheckBox
    End Sub

    [… according code for all other category check boxes…]

    These are the event subs, i.e. they are triggered as soon as the user clicks on the according check box. Nothing to explain here, I guess. The event subs simply call the subs defined in step 4.

Done.

Here is the workbook for free download:

Download Multiple Value Filter using ActiveX Checkboxes (Microsoft Excel 2003, 95K)

Approach 3 – Storing the Mixed Values

Let’s take approach 2 one step further. If you are having a lot of categories, it may be a nice idea to switch from a “mixed” combination (i.e. some categories checked and some unchecked) and all checked or all unchecked and back to the mixed combination. In other words: store the latest “mixed” selection.

Sounds easy at first sight, doesn’t it? Store the existing mixed combination somewhere and write the stored values back, if the value of the check box is set to Null (i.e. the grey check in the box).

But it isn’t that easy. Why? Because of an Excel oddity I wasn’t aware of. ActiveX controls have different event subs, like _Click (used above), _GotFocus, _Change, etc. Simple minded as I am, I assumed, _Change would be triggered if the value of the control is changed and _Click would be triggered if the user clicks on the control. The funny thing I learned is the fact that the event procedure _Click is also automatically called if you change the value of the control using VBA (i.e. there was no click on the check box). To be very honest, I do not really understand the difference of _Change and _Click.

The workaround for this oddity is using the _Click event only for the “All” check box and the _MouseUp event for all other check boxes.

The main steps in a nutshell:

  1. Define a cell range called “myStoredFilter”
  2. Use the _MouseUp event instead of _Click
  3. Assign the stored value in the sub Update_CheckBoxAll to the actual values, if the value of the “All” check box is Null (i.e. a “mixed” combination)
  4. Manipulate the value of the clicked check box before and after the IF-clause in the sub Update_SingleCheckBox to handle the oddity described above

If you are interested in the details, have a look at the VBA of the workbook. Here is the free download:

Download Multiple Value Filter with Store Mixed Values (Microsoft Excel 2003, 99K)

Recommendation

Let’s cut a long story short. First I thought approach 3 with storing the latest mixed combination would be the best and most user-friendly option. But it isn’t. If you play around with the workbook provided above you will notice very soon that it is more confusing than helpful.

So, let’s keep it simple. Most of the time, the form control approach will do the job, If you prefer having the greyed out check arrow for a mixed combination of checks, I recommend going with approach 2.

Acknowledgement

Many thanks go again to Matt Grams for the idea. I appreciate all of your contributions and inputs, Matt. Thanks!

What’s next?

I recently had the honor to do an Interview with Chandoo for the dashboard part of his great Excel School. We spent around 90 minutes discussing some techniques of creating interactive dashboards with Microsoft Excel. Due to the limited amount of time, we had to discuss a simplified example of an interactive Excel dashboard showing real estate KPIs in the Seattle region. The next post here will provide the fully blown interactive “Seattle Real Estate – Around the Sound” dashboard in Microsoft Excel.

Stay tuned.

Comments

17 responses to “Excel Dashboard Controls – Multiple Value Filters”

  1. Jeff Weir Avatar
    Jeff Weir

    Very cool. Here’s a thought: if you’ve got lots and lots of data, instead of having a Control row for each data series you could just point the chart directly to the Data page, and get the code to show/hide rows in the Data page accordingly.

  2. Jeff Weir Avatar
    Jeff Weir

    It seems to me there’s an error in how this works. Say a whole heap of things is selected, but you want to quickly select just one series. To my mind, the intend of your example is to deselect the ALL button, then select the various series one by one that you want.
    But what actually happens is after you deselect the ALL button, then select the first series that you want, the code kicks in and restores the previously stored series selection.

  3. Robert Avatar

    Jeff,
    many thanks for your comment.
    I agree: you could use some VBA to hide or show rows directly in the data sheet and point the chart series to the raw data. However, this would not fit anymore if you have other charts on the dashboard and the multiple value filter isn’t global (i.e. should not be applied to the other visualizations).
    Instead of hiding rows in the data source you could create named formulas (assigning N/A if the series isn’t checked) and use these named formulas as the data source of your chart. If you have a lot of data rows, you would probably write a one-off VBA solution to automatically create the named formulas and to assign them as the chart’s data source.

  4. Robert Avatar

    Jeff,
    “It is a feature, not a bug”.
    Just kidding. You are absolutely right. It is not helpful that the code of approach 3 is restoring the latest selection after deselecting all and clicking on one check box afterwards. This is definitely not what a user expects to happen.
    However, this is not an error. It rather is the bad design of the basic functionality of approach 3. When I started working on this article I thought storing the latest mixed selection would be a great idea. But it isn’t. As I wrote in the recommendation at the end of the post, it is confusing and unhelpful and I wouldn’t go with this approach.
    If it isn’t recommendable, why did I publish it? Well, I struggled quite a while with myself whether I should include it in the article or not. I finally decided to put it in, because it demonstrates the Excel oddity of the _Check and _Change events.
    Again, I fully agree with you. Stay away from approach 3, use approach 1 or 2 instead. They are intuitive and straight forward.

  5. dan l Avatar
    dan l

    Great post robert.

  6. Jon Peltier Avatar

    What’s nice is to restore the last settings in a dialog when it is relaunched. This prevents the user from having to reenter the same set of values.
    As Jeff has pointed out, in this case retaining values is not helpful to the user, so all that extra coding enhances the user experience, in a negative way.
    I prefer using forms menu controls for stability, especially across the 2003-2007 divide. Since the forms checkbox has no in-between setting, using an All checkbox is a bit unnatural. Often people will use a pair of regular buttons, All and None, which are static, and simply check or uncheck all of the other checkboxes.

  7. Robert Avatar

    Jon,
    thanks for your comment. As already written in the recommendation at the end of the article and in my reply to Jeff’s second comment, I would not use approach 3.
    Most of the time I am using the form controls, although they do not provide the TripleState value for a mixed setting of checked and unchecked boxes. I fully agree with your statements on the higher stability of form controls and the compatibility issues of ActiveX controls across Excel versions.
    However, I do not think an “all” checkbox is unnatural, even if it does not provided a grey check for indicating that some but not all categories are checked. From my point of view an “all” check box is more in line with the appearance of the whole filter than additional command buttons.
    A question of taste, I guess.

  8. Daniel Ferry Avatar

    Robert,
    This was a very interesting post!

  9. Robert Avatar

    Daniel,
    many thanks for your comment and appreciation. I deluded myself into believing this would be an interesting article until I saw what you did on your blog:
    Excel Dynamic Checkmark
    As always a blast! Thanks for sharing.

  10. Ulrik Avatar
    Ulrik

    Robert,
    Thanks for yet another well written and interesting post!
    I must admit, that the stored value option (approach 3) confused me a little (for the reasons already discussed above) but the other two approaches are very intuitive and easy to apply.
    The triple state checkmark comes in handy, if there are many categories to select from, allowing the user to easily see that some but not all are selected.

  11. Zilla37 Avatar
    Zilla37

    Is there a way to have that graph and check boxes duplicated below. There for you can have three graphs on one sheet almost like a dashboard with three data for different subjects?

  12. Robert Avatar

    Zilla37,
    thanks for your comment. Sure, you can have different check box filter controls for different charts.
    You have to
    1. Insert additional check boxes
    2. Link the new check boxes to a another cell range
    3. Add the new chart and change the formulas used in the chart’s data source referring to the new defined target cells of the new check boxes
    4. Finally duplicate the VBA subs, change them according to the names of your new checkboxes and assign the new subs to your new check boxes.
    A lot of laborious work, but no rocket science.
    Let me know if you have any further questions.

  13. Marko Avatar
    Marko

    Robert,
    that was very cool.
    I was hoping if you can provide some examples of using “combo boxes” drop down that are dependent on one another.
    i.e.
    A1:A2
    Fruits
    Veggies
    B1:B2
    Apple
    Organe
    C1:C2
    Eggplant
    Cucumber
    would that be do-able? thanks.

  14. Robert Avatar

    Marko,
    Sure, no sweat. Here is the how-to (based on your example):
    1. Insert a first form control combo box with an insert range A1:A2 and the cell link let’s say A3
    2. Create a named formula in the Name Manager and enter this formula: =INDEX(B$1:$C$2,,$A$3).
    3. Insert a second form control combo box. Set the cell link to e.g. B3 and use the name created in step 2 as the insert range.
    That’s it. I hope this will be helpful.

  15. Michel Avatar
    Michel

    Thanks! This is a great way to show how you could work with checkboxes. I’ve got something similar to use this for, yet this isn’t the solution. The problem is that I can’t use excel formulas to duplicate the data. What i’ve got is an array(vba code) with lots of data. I plot the data that equals certain conditions with an if else formula.
    This works fine with dropdown boxes. Not with multiple value filters since this can give 3 x 3 x 3 different values (Don’t want to do 27 if/else formulas :|) Checkboxes are used to show tasks based on who’s responsible for a task. Therefore the array consists of tasks for “me”, “Customer x”, “Customer Z”, “me and Customer X”, “me and Customer Y”. The filter you can check are: Show tasks to be done by: “Me”, “Customers” and/or “Me and Customer”.
    The question is how to use vba code to check which one, or two or three or none of the three checkbox’ is true and filter the array based on this.. (none wouldn’t show anything)
    Thanks in advance 🙂

  16. Michel Avatar
    Michel

    Ofcourse i meant 2 x 2 x 2 (since it’s either true or false)

  17. Robert Avatar

    Michel,
    I am not sure I fully understand this but it appears to be a simple Loop through the data and an IF … AND … THEN ELSE statement for filtering in VBA. If you want you send your workbook with some example data and the set up by email, I will have a look and post a solution here.

Leave a Reply to Zilla37 Cancel reply

Your email address will not be published. Required fields are marked *