Highlight a column in a stacked column chart
This interactive chart allows you to select a country by press with left mouse button oning on a spin button. The chart and table show the selected country.
I have made something very similar in the year 2013, Highlight a column in a stacked column chart but using Visual Basic for Applications (VBA). This article explains how to build and make it work without VBA.
What's on this webpage
- How to build a spin button (Form Control)
- How to configure a spin button
- How to link a spin button to a cell value?
- How to apply Conditional Formatting to an Excel table
- Copy Excel Table and new formulas
- Insert a column chart
- Color all stacked columns
- Add new data to chart
- Plot series on the secondary axis
- Delete secondary y-axis
- Get Excel file
The animated image above demonstrates a stacked column chart with a highlighted column based on the selected item using a spin button.
The corresponding row in the Excel Table is also highlighted and the selected country is displayed in cell C14.
1. How to insert a spin button (Form Control)
- Go to tab "Developer" on the ribbon.
- Press with left mouse button on the "Insert" controls button, see the image below.
- Press with left mouse button on "Spin Button" in group "Form Controls".
- Press and hold with left mouse button on the worksheet.
- Drag with mouse on the worksheet to size the spin button.
- Release the left mouse button.
2. How to configure spin button
- Press with right mouse button on on spin button
- Press with left mouse button on "Format Control..."
- Go to tab "Control"
- Change the maximum value, if you have 10 countries use value 10. 20 countries use value 20.
- Select a cell to link the spin button to, see the image above.
- Press with left mouse button on OK button to apply changes.
3. How to link a spin button to a cell value?
Cell C14 shows the selected country, the cell is linked to the spin button using a formula and refreshes every time you press with left mouse button on the spin button.
- Double-press with left mouse button on with left mouse button on cell C14.
- Type this formula:
=INDEX(Table13[Country],D14)
- Press Enter.
The value changes in cell C14 when you press with left mouse button on the spin buttons. The spin button is linked to cell D14.
The formula in cell C14 then uses the value in cell D14 to get the country name in column Country in table Table13. The value is shown in cell C14.
4. How to apply Conditional Formatting to an Excel table
- Select all values in the Excel Table.
- Go to tab "Home" on the ribbon.
- Press with left mouse button on the "Conditional formatting" button.
- Press with left mouse button on "New Rule...". A dialog box appears on the screen, see the image below.
- Press with mouse on "Use a formula to determine which cells to format" to select it.
- Type in "Format values where this formula is true:"
=$C$14=INDIRECT("Table1[@Country]")
- Press with left mouse button on "Format..." button. Another dialog box appears.
- Pick a color.
- Press with left mouse button on OK button to return to the first dialog box.
- Press with left mouse button on OK button to dismiss the first dialog box.
This formula
compares the value in cell C14 with each of the values in column Country, Table13. If a value is a match the entire row is highlighted.
Explaining Conditional Formatting formula
Step 1 - Create a structured reference
A cell reference pointing to a value in an Excel Table is different than regular cell references.
Table13[@Country]
The first value is the Table name, in this example: Table13
The item in brackets is the column name in the Excel Table, the @ character points to a cell that is on the same row as the CF formula itself.
Table13[@Country]
Step 2 - Workaround for Excel Tables in CF formulas
The INDIRECT function is needed in order to use a structured reference in a Conditional Formatting formula.
INDIRECT("Table13[@Country]")
Step 3 - Compare values in column "Country" to value in cell C14
The equal sign lets you compare two or more values to a condition.
$C$14=INDIRECT("Table13[@Country]")
An expression using logical operators (equal sign is one of them) is called a logical test or logical expression. The return TRUE or FALSE or their equivalent numerical digit TRUE - 1 or FALSE - 0 (zero).
The Conditional Formatting formula highlights the row if the logical expression returns TRUE and nothing happens if it evaluates to FALSE.
5. Copy Excel Table and new formulas
- Copy table13
- Paste it next to table 13 but keep at least one blank column between tables.
(Press with left mouse button on to enlarge) - Delete all values except headers in the new table
- Select the first cell (I3) in the new table and type: =IF(Table13[@Country]=$C$14,Table13[@Country],""). You don´t need to copy the formula to cells below, the table takes care of that.
- Cell J3: =IF([@Country]<>"",Table13[@[GDP (nominal)]],"")
- Cell K3: =IF([@[GDP (nominal)]]<>"",Table13[@[GDP per capita (nominal)]],"")
- Cell L3: =IF([@[GDP (nominal)]]<>"",Table13[@Agricultural],"")
- Cell M3: =IF([@[GDP per capita (nominal)]]<>"",Table13[@Industrial],"")
- Cell N3: =IF([@[GDP per capita (nominal)]]<>"",Table13[@Service],"")
(Press with left mouse button on for larger picture)
We are using the second table to populate the second series in a chart. If this doesn't make sense to you, don't worry.
6. Insert a column chart
- Select table13 data.
- Go to tab "Insert".
- Press with left mouse button on "Column Chart" button.
- Press with left mouse button on "Stacked Column" button.
- Press with right mouse button on on chart and press with left mouse button on "Select Data...".
- Remove GDP (nominal).
- Remove GDP per capita (nominal).
- Press with left mouse button on OK.
This is what the chart looks like now.
7. Color all stacked columns
- Press with right mouse button on on a column
- Press with left mouse button on "Format Data Series...".
- Press with left mouse button on "Fill".
- Press with left mouse button on "Solid Fill".
- Pick a color.
- Press with mouse on the next column series on the chart.
- Repeat step 3 to 5 with all remaining column series.
8. Add new data to chart
- Press with right mouse button on on the chart.
- Press with left mouse button on "Select Data...".
- Press with left mouse button on the "Add" button.
- Add series "Agriculture", "Industrial" and "Services" from the second table (not table13).
9. Plot series on the secondary axis
- Press with right mouse button on on one of the new column series.
- Press with left mouse button on "Format Data Series...".
- Press with left mouse button on "Plot Series On Secondary Axis".
- Go to tab "Layout" on the ribbon.
- Select one of the remaining new series (Agriculture, Services and Industrial).
- Repeat step 3.
- Make sure you have moved Agriculture, Services, and Industrial series to the secondary axis.
10. Delete secondary y-axis
- Select secondary y-axis.
- Press Delete.
Charts category
Question: How do I create a chart that dynamically adds the values, as i type them on the worksheet? Answer: […]
I recently discovered an interesting technique about using a user defined function in a HYPERLINK function. Jordan at the Option […]
In this article I will demonstrate how to quickly change chart data range utilizing a combobox (drop-down list). The above […]
Column chart category
This article demonstrates macros that automatically changes the chart bar colors based on the corresponding cell, the first example is […]
This article demonstrates how to create a chart that animates the columns when filtering chart data. The columns change incrementally […]
This tutorial shows you how to add a horizontal/vertical line to a chart. Excel allows you to combine two types […]
Highlight category
This article demonstrates how to highlight a bar in a chart, it allows you to quickly bring attention to a […]
This article demonstrates how to highlight a line in a chart based on the selected item in a drop-down list. […]
This article demonstrates how to highlight a group of bars in a chart bar, the techniques shown here works fine […]
Functions in this article
More than 1300 Excel formulas
Excel categories
3 Responses to “Highlight a column in a stacked column chart”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Общественный магазин где каждый может продать запчасти которые остались после тюнинга, ремонта и других улучшений автомобиля, в нашей базе знаний вы найдете как настроить машину на ECU VEMS и поставить JZ-GTE в любой автомобиль
LoveDatingClub.ru the most popular dating site for serious relationship! The perfect place to find new friends, interesting Dating and communication.
Интернет-магазин качественных наручных часов с доставкой по всей Украине. Хороший асортимент продукции позволит каждому найти что-то для себя. Наши менеджеры всегда готовы проконсультировать вас и в кратчайшие сроки оформить и выслать заказ.