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.
Built-in Charts
Combo Charts
Combined stacked area and a clustered column chartCombined chart – Column and Line on secondary axis
Combined Column and Line chart
Chart elements
Chart basics
How to create a dynamic chartRearrange data source in order to create a dynamic chart
Use slicers to quickly filter chart data
Four ways to resize a chart
How to align chart with cell grid
Group chart categories
How to add lines between stacked columns/bars [Excel charts]
Custom charts
How to build an arrow chartHow to graph a Normal Distribution
How to graph an equation
Build a comparison table/chart
Heat map yearly calendar
Advanced Gantt Chart Template
Sparklines
Win/Loss Column LineHighlight chart elements
Highlight a column in a stacked column chartHighlight a group of chart bars
Highlight a data series in a line chart
Highlight a column in a stacked column chart
Highlight a bar in a chart
Interactive charts
How to filter chart dataHover with mouse cursor to change stock in a candlestick chart
How to build an interactive map in Excel
Highlight group of values in an x y scatter chart programmatically
Use drop down lists and named ranges to filter chart values
How to use mouse hover on a worksheet [VBA]
How to create an interactive Excel chart [VBA]
Change chart series by clicking on data [VBA]
Change chart data range using a Drop Down List [VBA]
How to create a dynamic chart
Animate
Line chart Excel Bar Chart Excel chartAdvanced charts
Custom data labels in a chartImprove your X Y Scatter Chart with custom data labels
Label line chart series
How to position month and year between chart tick marks
How to add horizontal line to chart
Add pictures to a chart axis
How to color chart bars based on their values
Excel chart problem: Hard to read series values
Build a stock chart with two series
Change chart axis range programmatically
Change column/bar color in charts
Hide specific columns programmatically
Dynamic stock chart
How to replace columns with pictures in a column chart
Color chart columns based on cell color
Heat map using pictures
Dynamic Gantt charts
Stock charts
Build a stock chart with two seriesDynamic stock chart
Change chart axis range programmatically
How to create a stock chart
Excel categories
One Response to “How to create a stock chart”
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.
[…] Learn how to create a stock chart in excel […]