In this post, I would like to pick up the example we looked at last week. We saw that it is possible to highlight specific values in a bar chart. This makes it very easy for the reader to see the key information quickly. In this post, we will consider a similar goal, but for tables. How can we highlight a specific row in a table to draw attention to it? We will also add a little bit of interactivity to this example by using a combo box to select the value we wish to highlight.
The source data
We will be using the same source data as before. However, to keep things simple, we will assume that this data is already sorted (if you want to follow an example with unsorted data then follow the first part of last weeks’ post).
Creating the combo box
We will be using a combo box to select the row we wish to highlight. A combo box is a type of input box which lets you select from a list (you’ll recognize it when you see it). To create a combo box you will need the Developer Ribbon enabled.
Right-click on a blank part of the ribbon and select Customize the Ribbon… from the menu
From the Excel Options window click Customize Ribbon, enable the Developer option then click OK.
Then click Developer -> Insert -> Combo Box (Form Control).
There is also a combo box in the ActiveX controls section, it is similar to the one we are using, but has a few different options. For this example, we will stick with the Form Control version.
The mouse will become a + shape. Click and drag a shape to represent the size and location where the combo box should be. I have created a combo box as shown below.
Next, right click on the combo box and select Format Control….
The Format Control window will appear. There are two boxes to be completed:
- Input range – select the cells representing the list of companies.
- Cell link – select the cell to display the selected value.
Now we can use the combo box to select values. In the screenshot below I have selected Fox Books, this has a value of 3 as it is the 3rd item in the list.
Using INDEX to get the company name
The problem is that we want to match the company name of Fox Books, not the location in the list. So, in Cell F3 we can use the INDEX function to obtain the company name.
Cell F3 contains the following formula:
The formula is requesting the 3rd result (Cell E3) from the array of values (Cells A2-A8). The result is Fox Books.
Highlighting the row
We will now use conditional formatting to highlight the row which matches the value in Cell F3.
Select the cells to be highlighted, click Home -> Conditional Formatting -> New Rules.
The New Formatting Rule window will open. Select the last option in the list Use a formula to determine which cells to format.
Next, we need to create our formula. Our formula is:
The formula is written for the cell which is highlighted in the selected range (Cell A2 as shown below) but is applied to the whole range (Cells A2-B8).
The $ symbols are used in the formula to freeze the cell reference, just like normal in formulas. Therefore, when Excel gets to Cell A3 it knows the formula should be as follows:
Equally, it will create the formula for Cells A4, A5 etc all the way down to A8.
Click Format, and select the formatting you wish. I’ve chosen a mid-grey fill, so as not to over-power everything. Click OK, OK again, then OK one more time. You should now be back to your worksheet with the selected row highlighted.
We can test the highlighting by changing the value in the combo box – Ta-Dah! The highlighting now changes as the selection changes. You just need to format it to look nice and you’ve now got an interactive table, which could be used on a dashboard.
Get our FREE VBA eBook of the 30 most useful Excel VBA macros.
Automate Excel so that you can save time and stop doing the jobs a trained monkey could do.
If you’ve found this post useful, or if you have a better approach, then please leave a comment below.
Do you need help adapting this to your needs?
I’m guessing the examples in this post didn’t exactly meet your situation. We all use Excel differently, so it’s impossible to write a post that will meet everybody’s needs. By taking the time to understand the techniques and principles in this post (and elsewhere on this site) you should be able to adapt it to your needs.
But, if you’re still struggling you should:
- Read other blogs, or watch YouTube videos on the same topic. You will benefit much more by discovering your own solutions.
- Ask the ‘Excel Ninja’ in your office. It’s amazing what things other people know.
- Ask a question in a forum like Mr Excel, or the Microsoft Answers Community. Remember, the people on these forums are generally giving their time for free. So take care to craft your question, make sure it’s clear and concise. List all the things you’ve tried, and provide screenshots, code segments and example workbooks.
- Use Excel Rescue, who are my consultancy partner. They help by providing solutions to smaller Excel problems.
Don’t go yet, there is plenty more to learn on Excel Off The Grid. Check out the latest posts: