Filtering is one of the most used feature in Excel. It is a quick way to take lots of data and narrow down to the subset we want.
Naturally, there are many powerful ways to work with filters. To name a few,
- Using CTRL+Shift+L shortcut to quickly turn on / off the filters
- Right clicking on a cell value and choosing filter > filter by selected cell’s value
- Using advanced filters to set up complex filtering conditions
But here is one common filtering scenario that is slow as snail.
Imagine you are looking at some sort of sales data (if you can’t imagine, look at the below demo).
Now, you want to filter this list for a combination like, gender=male, profession=self-employed, product category = chocolates and quantity = 1.
If you use the right click, filter > filter by selected value approach, this will take several clicks.
Wouldn’t it be cool if you can select the entire combination and say filter?
Unfortunately, no such feature exists in Excel.
But you are not aiming to be ordinary in Excel. You are aiming to be awesome in Excel. That means, you don’t take no for answer.
Fortunately, we can quickly write a VBA macro that filters a list by selection. So let’s do that. Here is what you will learn to create:

Filtering a table by selected combination of values using VBA
What we need to achieve?
Our goal is simple. User (that is you) selects a range of cells depicting the conditions for filtering. Something like this.
After selection, we fire up the filtering macro and instantly our list is filtered.
We can select a single-range or multiple cells (using CTRL+select technique)
Just to keep things simple, let’s assume the data is always in a table.
Algorithm / Steps for the VBA macro
Whenever you attempt to write VBA code, it is a good idea to start by writing down the steps in plain English. This is called as algorithm. By writing down the steps, we force our mind to think clearly about the problem at hand and come up with best possible solution.
Here are the steps for filtering the table by selected combination
- Make sure user has selected some values in a table
- Check if more than one row is selected. If so, exit as we don’t want to filter based OR conditions, we just want to filter based on AND conditions.
- For each cell in the selection
- Find out the corresponding column number
- Apply filtering on the table for corresponding column number with the cell’s value
- Repeat for next cell
- Done
VBA code – Filtering based on selected combination
Here is the VBA code for filtering based on selected combination. First examine the code. Then, we will understand key segments of it.
Sub combinationFilter()
Dim cell As Range, tableObj As ListObject, subSelection As Range
Dim filterCriteria() As String, filterFields() As Integer
Dim i As Integer
'If the selection is in a table and one row height
If Not Selection.ListObject Is Nothing And Selection.rows.Count = 1 Then
Set tableObj = ActiveSheet.ListObjects(Selection.ListObject.Name)
i = 1
ReDim filterCriteria(1 To Selection.Cells.Count) As String
ReDim filterFields(1 To Selection.Cells.Count) As Integer
' handle multi-selects
For Each subSelection In Selection.Areas
For Each cell In subSelection
filterCriteria(i) = cell.Text
filterFields(i) = cell.Column - tableObj.Range.Cells(1, 1).Column + 1
i = i + 1
Next cell
Next subSelection
With tableObj.Range
For i = 1 To UBound(filterCriteria)
.AutoFilter field:=filterFields(i), Criteria1:=filterCriteria(i)
Next i
End With
Set tableObj = Nothing
End If
End Sub
How does the combinationFilter() macro work?
Checking if selected cells are inside a table
We start by checking if the selection is inside a table by checking if the Selection.ListObject is not nothing. (Aside: there is no direct way to ask if there is a listobject. So we ask indirectly, by saying Not Selection.ListObject Is Nothing.)
Once we know that Selection is inside a table, we grab the table object and set it to the variable tableObj.
Finding out what to filter
To set filters on a table, we need to know the field number (ie column number inside the table) and filter criteria.
Filter criteria is denoted by cell values in the selection.
We are extracting filter criteria values & determining the column numbers for each of the selection’s cells using a simple For Each loop.
Setting up the filters
Once all the filter criteria are determined, we simply loop thru the criteria and set the filters on table using tableObj.Range.AutoFilter method.
How to use this macro for your data?
This macro is designed to work with any table. I have tested it in Excel 2010 & Excel 2013 and it seems to work alright.
To use it with your data, follow below steps.
- Open your personal macros file
- Copy the combinationFilter() macro and paste it in your Personal Macros workbook in a module
- Save and close personal macros file.
- Add this macro to Excel ribbon or quick access toolbar (QAT)
- To add to ribbon: Refer to below picture.

- To add to Quick Access Toolbar – click here for instructions.
- To add to ribbon: Refer to below picture.
- Once you select the combination to filter, click on the ribbon / QAT button.
- Done!
Download Selected Combination Filter Macro
Please click here to download the example workbook. Play with the macro to understand it better.
New to VBA? Learn how to exploit its awesome power
If you are new to VBA, you might find above example both awesome & hard to digest. But don’t worry. Start with this simple crash course on VBA. Check out more VBA examples. Very soon you will be automating parts of your work and impressing your boss. All the best.
Do you find the combination filter useful?
When I first thought about this macro, I feared the code might be too long or confusing. But I am happy with the outcome. It is a crisp, simple and powerful macro that I can use often when working with lots of data.
What about you? Do you find this macro useful? How are you planning to deploy it for your work situations. Let me know in the comments area.


















31 Responses to “Beautiful Budget vs. Actual chart to make your boss love you”
Would be considerably easier just to have a table with the variance shown.
On Step 3, how do you "Add budget and actual values to the chart again"?
There are a few ways to do it.
Easy:
1) Copy just the numbers from both columns (Select, CTRL+C)
2) Select the chart and hit CTRL+V to paste. This adds them to chart.
Traditional:
1) Right click on chart and go to "select data..."
2) From the dialog, click on "Add" button and add one series at a time.
One more way to accomplish it is just select the columns into chart. Press Ctrl+C and then press Ctrl+V
Regards
Neeraj Kumar Agarwal
Unfortunately, this doesn't seem to work for me in Excel 2010. The "Var 1" and "Var 2" columns cannot combine two fonts to display the symbol and the figure side-by-side.
Secondly, there is no option to Click on “Value from cells” option when formatting the label options. The only options provided are Series Name, Category Name or Value.
@TheQ47... the emoji font also has normal English letters, so if you use that font, then you should be ok. I am assuming your computer doesn't have that font or hasn't been upgraded for emoji support.
Reg. Excel 2010, you can manually link each label to a cell value. Just select one label at a time (click on labels, wait a second, click on an individual label) and press = and link it to the label var 1 or var 2.
I am using excel 2010, please explain how to apply Step 12
Regards
Neeraj Kumar Agarwal
Hi Neeraj,
"Value from cells" option is only available in Excel 2013 or above. In older versions, you have to manually adjust the label value by linking each label seperately.
Read this please: https://chandoo.org/wp/change-data-labels-in-charts/
Sir, you are just awesome.
Your creativity has no limit.
Regards
Neeraj Kumar Agarwal
Hi Chandoo,
I just found your website, and really love it. It helps me a lot to be an Excel expert 😉
Currently I am facing with a problem at step 11:
Var1 Var2
D30%
A5%
B0%
B4%
B7%
C10%
C13%
D27%
I42%
Though at mapping table, I used windings, here formula uses calibra. How I can change it? I am able to change only the whole cell. In this case numbers will be Windings too.
Thanks for your help!
Hi Mariann... Welcome to Chandoo.org and thanks for your comment.
If you wanted to use symbols from wingdings and combine them with % numbers, then you need to setup two labels. One with symbol, in wingdings font and another with value in normal font. Just add the same series again to the chart, make it invisible, add labels. You may need to adjust the alignment / position of label so everything is visible.
[…] firs article explains how you can enhance your charts with symbols. You can simply insert any supported symbol into your data and charts. To some extend you can […]
You're a good person, thank you to share your knowledge with us, I will try to do in my work
Great visualization of variance. My question is that is this possible in powerbi?
How would you go about it?
HELLO, WHY CANT I FIND VALUES FOR LABELS IN EXCEL 2013
Dear chanddo sir,
What to do if we have dynamic range for Chart. How this will work. can you able to make the same thing works on dynamic range.
Sir Chandoo,
Good Day!
First, I'd like to say that I am very grateful for your work and for sharing all these things with us.
I tried to do this chart but it seems that the symbols don't work with text (abs(var%),"0%") unless we keep the Windings font style.
The problem is, it converts the text into symbol as well and you wont see the 0% anymore. I'm using Windows 7.
WOW - Segoe UI Emoji
This is the greatest discovery for me this month 🙂 Thanks for sharing.
Here's my two-cents:
https://wmfexcel.com/2019/02/17/a-compelling-chart-in-three-minutes/
Sir This is awesome chart, and very easy to made because of your way to explain is very simple , everyone can do. Thank you
one problem i am facing, I hv made this chart , but when i am inserting data table to chart it is showing two times , how can i resolve this
in this chart when i am adding new month data for example first i made this chart jan to mar but when i add data for the apr month graphs updated automatically but labels are missing for that new month
Hi Renuka,
Please make sure the formulas for labels are also calculated for extra months. Just drag down the series and set label range to appropriate address.
So I am playing with the Actual chart here - but amounts are bigger than your - you have 600 as Budget - my budget is 104,000 - is there a way to shorten that I am unaware of
thank you - I LOVE YOUR SITE
Thanks for the tips and tricks on Excel. In the Planned versus Actual chart examples, you use multiple values (ex. multiple Categories in above). How can this be done when we have only 1 set of values? For example if I have only this:
Planned Actual
SOW Budget 417480 367551
How can I create a single bar chart like the one above?
Thank you Chandoo.
This one is just perfect for my Quarterly Review presentation on Operational Budget against Actual Performance for the Hospital I'm currently working with.
Just Subscribed today (10 minutes ago)
Is there a way to make the table of data into a pivot table to be able to add a slicer for the graph due to many different categories and months?
Hi, I tried to modify you template with something appropriate for me, and I found a problem. this template was modified by me started with excel 2010, then 2016 and finally 2019. Same thing - somehow appear an error - or didn't show the emoticons for positive percentage or doubled the emoticons for some rows. I suspect to be from excel. if is need it I can sand you my xlsx for study. Please help if you can.
Hi Chandoo,
Could you please check the Var Formula in Step1. You have mentioned budget-actual and when i did this i got different values but when reversed like actual-budget i got the actual value what you have demonstrated in step1.
Please share your view.
This is a great chart (budget vs. actual). However, in trying recreate it, I cannot color in the UP Down bars individually, and they all become formatted with the same color. I'm using Office 365. Look forward to the feedback.
Thanks.
Dan
pls explain in detail step 7
While in the Excel sheet you have used following formula for Var
Var = Actual - Budget
But
in the note, you have written
Var = Budget - Actual
Good Presentation and Data information.thank you so much chandoo.