This is a guest post by Myles Arnott from Clarity Consultancy Services – UK.
- Part 1: Introduction & overview
- Part 2: Dynamic Charts in the Dashboard
- Part 3: VBA behind the Dynamic Dashboard a simple example
- Part 4: Pulling it all together
In this post we are going to look at a simple example of the VBA behind the Dynamic Dashboard. Essentially we will learn to write macros for doing this:
The dynamic dashboard VBA example can be downloaded here [Mirror]
Some VBA essentials
Defining variables:
First we need to define variables “left” and “top” as integers.
Dim left As Integer
Dim top As Integer
Next we need to set a value for these variables. To do this I have created two named ranges in the Excel file called Left and Top. To make variable “left” equal to named range Left:
left = Range("Left").Value
and the equivalent for variable “top”
top = Range("Top").Value
Finally select the shape:
ActiveSheet.Shapes("Rounded Rectangle 1").Select
And define its position:
Selection.ShapeRange.top = top
Selection.ShapeRange.left = left
So the full code is:
Sub move_Image()
Dim left As Integer
Dim top As Integer
'Define the position values
left = Range("Left").Value
top = Range("Top").Value
'Select the shape and position it
ActiveSheet.Shapes("Rounded Rectangle 1").Select
Selection.ShapeRange.top = top
Selection.ShapeRange.left = left
End Sub
This code can be viewed by clicking on macros in the file.
Once you have the code ready, you should assign it to the Rounded Rectangle 1, so that whenever you click on the rounded rectangle, the code is run.
What it does
In the downloadable file in Sheet1, enter values against the Top and Left positions in the input area (blue). Click on the shape to move it to the position you have defined.
How it works
Clicking on the shape runs macro “move_Image”.
The value for the position of the shape is linked from the named range to the variable.
The macro uses Selection.ShapeRange.top and Selection.ShapeRange.left to determine the position of the shape based on the variable value.
What Next?
We now know how to move objects using VBA. In the final part of the series learn how to pull all this together to create the dashboard.
Download the complete dashboard
Go ahead and download the dashboard excel file. The dynamic dashboard can be downloaded here [mirror, ZIP Version]
It works on Excel 2007 and above. You need to enable macros and links to make it work.
Added by PHD:
Myles has taken various important concepts like Microcharts, form controls, macros, camera snapshot, formulas etc and combined all these to create a truly outstanding dashboard. I am honored to feature his ideas and implementation here on PHD. I have learned several valuable tricks while exploring his dashboard. I am sure you would too.
If you like this tutorial please say thanks to Myles.
Related Material & Resources
- Excel Dynamic Charts – Tutorials, Examples and Demos
- Excel Dashboards – Tutorials & Templates Section of PHD
- 6 Part Tutorial on Making KPI Dashboards in Excel
This is a guest post by Myles Arnott from Clarity Consultancy Services – UK.
6 Responses to “Making a Dynamic Dashboard in Excel [Part 3 of 4]”
I got an error because "Scrolling Chart Example.xls" is not available.
@Charley.. Can you explain when you are getting this error? Which file?
I got an errror opening the complete dashboard file, Dynamic Dashboard Illustration V1.1.xlsm.
It happened after enabling the macros, with the option to edit links.
In the edit link dialog screen, there is a link mentioned "Scrolling Chart Example.xls".
I could not find any formula that used this file in it.
I also looked at the declared names. A lot of #REF!s in the name manager dialog screen.
But no "Scrolling Chart Example.xls", as far as I could see.
I sometimes get a link error in my own excelsheets and I can't find where it originates from. It looks like the source of the error is a chart, which stays linked to an external sheet. The link is not visible anywhere, so it is very difficult to find out where the link is coming from and how to correct it. The only solution I could find, was deleting the chart and making it from scratch.
I get the same error when opening the Dynamic Dashboard Illustration V1.1.xlsm file. Is the Scrolling Chart Example.xls spreadsheet available for download?
I was looking for the help menu as well. Luckily I found it. Here is the link to John's page.
http://spreadsheetpage.com/index.php/tip/displaying_help/
Thanks for this four-part tutorial!