dynamic chart switcher

27
Copyright © 2011 Techronology. All rights reserved. Dynamic Chart with Dropdown List Control February 18, 2011

Upload: techronology-inc

Post on 24-May-2015

4.281 views

Category:

Documents


0 download

DESCRIPTION

Illustrated tutorial on how to create a dynamic chart in Microsoft Excel 2007

TRANSCRIPT

Page 1: Dynamic Chart Switcher

Copyright © 2011 Techronology. All rights reserved.

Dynamic Chart with Dropdown List ControlFebruary 18, 2011

Page 2: Dynamic Chart Switcher

Overview

We will create a chart in Microsoft Excel that updates automatically based on a selection from an in-cell dropdown list

This chart will function based on quarterly figures as its data source

The main purpose is to show users the dynamic functionality of Microsoft Excel without using macros

Copyright © 2011 Techronology. All rights reserved.

Page 3: Dynamic Chart Switcher

Quick Glance

The components Dropdown selection list Categories and data Dynamic chart

The idea To be able to change the chart's

data source based a user's selection

Again, we will not show you how to create the dropdown list itself, which is covered in a separate lesson

Copyright © 2011 Techronology. All rights reserved.

Page 4: Dynamic Chart Switcher

Requirements

Microsoft Excel 2007 You may be able to apply the instructions in this tutorial to other versions of

Microsoft Excel

Optional Check out the tutorials below on creating dropdown lists in Microsoft Excel

(We will not cover the creation of dropdown lists in this tutorial)

Copyright © 2011 Techronology. All rights reserved.

Tutorial Links

http://www.slideshare.net/techron/incell-interactivity-dropdown-box-in-excelhttp://www.techronology.com/index.php?pageID=007002&lessonID=excel0001&lessonType=pres

Page 5: Dynamic Chart Switcher

Get the Data Ready

This data refers to the amount of money spent on business supplies and stationary for a particular business

Below is the data you should use in this lesson

Copyright © 2011 Techronology. All rights reserved.

Supply 1st Qtr 2nd Qtr 3rd Qtr 4th QtrMemo Pads $100 $110 $150 $180 Pencils $30 $20 $25 $25 Staplers $400 $150 $200 $300

We have our data organized in cells D5 to H8, as shown below

Page 6: Dynamic Chart Switcher

Enter the Data

Enter the data (in cells D5 to H8) for your chart using the same numbers as below

Copyright © 2011 Techronology. All rights reserved.

Page 7: Dynamic Chart Switcher

Create the In-cell Dropdown List

In cell B6, create an in-cell dropdown list with four choices 1st Quarter 2nd Quarter 3rd Quarter 4th Quarter

Copyright © 2011 Techronology. All rights reserved.

Page 8: Dynamic Chart Switcher

Select Your Data and Prepare to Create Chart

Select cells D5 to E8, which will serve as your initial data for your chart

Click on the Insert menu

Copyright © 2011 Techronology. All rights reserved.

1 1

2

2

Page 9: Dynamic Chart Switcher

Create a Standard Pie Chart

Click on the Pie icon Click on the first pie icon

in the 2-D Pie section

Copyright © 2011 Techronology. All rights reserved.

Page 10: Dynamic Chart Switcher

Chart Display

You can move the chart around, resize it, etc., but it is time to make the chart more dynamic

Now that the chart is created, let's make some named ranges that will work with the chart

Copyright © 2011 Techronology. All rights reserved.

Page 11: Dynamic Chart Switcher

Create the Named Ranges for First Two Quarters

Select cells E6 to E8 Type qtrData1 in the

Name Box and press Enter

Select cells F6 to F8 Type qtrData2 in the

Name Box and press Enter

We cover named ranges in a previous tutorial, which is listed on the Requirements page in the beginning of this tutorial

Copyright © 2011 Techronology. All rights reserved.

1

2

1

2

Page 12: Dynamic Chart Switcher

Finish Creating the Named Ranges

Select cells G6 to G8 Type qtrData3 in the

Name Box and press Enter

Select cells H6 to H8 Type qtrData4 in the

Name Box and press Enter

Copyright © 2011 Techronology. All rights reserved.

1

2

1

2

Page 13: Dynamic Chart Switcher

Test the Dropdown List

We now want to supply a number based on the user's selection Below are the index values we want to use for the dropdown list– 1st Quarter = 1– 2nd Quarter = 2– 3rd Quarter = 3– 4th Quarter = 4

So, when a user selects 3rd Quarter, for example, the value 3 should be applied

Copyright © 2011 Techronology. All rights reserved.

Page 14: Dynamic Chart Switcher

Match Up Your Choice

Type the formula shown above in cell B8 and press Enter

The MATCH function searches for a specified item in a range and then returns the relative position of that item in the range

In our case, the range is {"1st Quarter","2nd Quarter","3rd Quarter","4th Quarter"}

Copyright © 2011 Techronology. All rights reserved.

Page 15: Dynamic Chart Switcher

Our Match Formula Breakdown

The final result should be 1, 2, 3, or 4 in cell B6

If a match cannot be found, an error is displayed

Our dropdown list should only allow the values listed in the match range; therefore, an error should not occur

Copyright © 2011 Techronology. All rights reserved.

=MATCH($B$6,{"1st Quarter","2nd Quarter","3rd Quarter","4th Quarter"},0)

This is the value in cell B6 we want to lookup

These are the range of values to check B6 against

The zero value in MATCH looks for an exact match

Page 16: Dynamic Chart Switcher

Creating the Series Names from User Selections

We can now append the number produced in B6 to the text "qtrData"

For example, if the user selects "2nd Quarter" then B6 will equal 2 and the text "qtrData" will become "qtrData2"

Below are the text values that we want to create based on the user selection 1st Quarter = "qtrData1" 2nd Quarter = "qtrData2" 3rd Quarter = "qtrData3" 4th Quarter = "qtrData4"

Copyright © 2011 Techronology. All rights reserved.

Page 17: Dynamic Chart Switcher

Test the Series Text Name

In cell B9, enter the follow formula (including the quotations)…

="qtrData"&B8

…which will produce qrtData1, qrtData2, qrtData3, or qrtData4

Copyright © 2011 Techronology. All rights reserved.

Remember, cell B8 is the same as…

=MATCH($B$6,{"1st Quarter","2nd Quarter","3rd Quarter","4th Quarter"},0)

Page 18: Dynamic Chart Switcher

Finalize Series Name

In cell B10, combine cell B8 and B9 using the following formula…

="qtrData"&MATCH($B$6,{"1st Quarter","2nd Quarter","3rd Quarter","4th Quarter"},0)

This will become our master named range for the chart series

Copyright © 2011 Techronology. All rights reserved.

Page 19: Dynamic Chart Switcher

Get the Formula for the Series Name

Click on cell B10 Press function key 2 (F2)

to go into edit more Select all the text,

including the equal sign Press Ctrl-C to copy the

formula

Or… Select and copy the

formula from the formula toolbar

Copyright © 2011 Techronology. All rights reserved.

1

2

1

2

Page 20: Dynamic Chart Switcher

Create the Series Named Range

Click Formulas from the menu

Click Define Name from the Formulas ribbon

Type seriesData as the Name

Paste in the formula you copied from cell B10 to the Refers to box

Press Enter or click OK

You may need to try this twice or type in the formula directly to get use to the procedure

Copyright © 2011 Techronology. All rights reserved.

1

2

1

2

Page 21: Dynamic Chart Switcher

Make the New Range Name an Indirect Range

Open the Name Manager by pressing Ctrl-F3 or by clicking Name Manager from the Formulas ribbon (see previous page)

Click on seriesData In the Refers to box,

enclose everything in parenthesis

Before the first parenthesis, type INDIRECT

See the complete formula below

Copyright © 2011 Techronology. All rights reserved.

=INDIRECT("qtrData"&MATCH(Sheet1!$B$6,{"1st Quarter","2nd Quarter","3rd Quarter","4th Quarter"},0))

Page 22: Dynamic Chart Switcher

INDIRECT Function Note

INDIRECT returns the reference specified by a text string. References are immediately evaluated to display their contents. Use INDIRECT when you want to change the reference to a cell within a formula without changing the formula itself.

Copyright © 2011 Techronology. All rights reserved.

Page 23: Dynamic Chart Switcher

Apply Your New Range Name to the Chart

Right-click on a white area on the chart to view the shortcut menu

Click Select Data from the shortcut menu

You can also click on the chart, select Design from Chart Tools, and click on the Select Data icon

Copyright © 2011 Techronology. All rights reserved.

Page 24: Dynamic Chart Switcher

Create New Data Source

Click on 1st Qtr and then click the Edit option

Under Edit Series, type Sheet1!seriesData in the Series values box

Press Enter or click OK

Basically, what you are doing is typing the name of your sheet, the exclamation point, and the named range

If your sheet's name is not "Sheet1" replace "Sheet1" with the name of your sheet

Copyright © 2011 Techronology. All rights reserved.

1

2

1

2

Page 25: Dynamic Chart Switcher

Test Your Chart

Now when you select an option from the dropdown, the chart will update automatically according to your selection

On the other hand, the series name or title will not change because you did not create a dynamic range name for them yet

You really do not need to unless you plan on displaying a chart or series title

Simply click on the chart title and press delete

Copyright © 2011 Techronology. All rights reserved.

Page 26: Dynamic Chart Switcher

End Notes

You can now delete the contents of the test cells (B8, B9, and B10)

This technique can work with almost any kind of chart

Once you get really good, you can create charts that automatically adjust to the size of a range

You can get the supporting Microsoft Excel file from the following site:

http://www.techronology.com/products.php?prodID=less002

Copyright © 2011 Techronology. All rights reserved.

Page 27: Dynamic Chart Switcher

www.techronology.com