Everyone! We've moved to WordPress.

Are You Series(ous)?

0
Do you work with different series in your Excel charts?

Here is what I would like the final chart to loo like. Note the white dashed lines in front of the columns:

Setup:

I started with the chart I ended with in my last post, Points Of Interest.



I then added some data to a separate worksheet in my workbook to replicate the horizontal gridlines.

The horizotal gridline scale is in units of 10, so I will use the same scale for my series' that I create for the "fake" gridlines.







Note in Col A that I used the exact same scale that I used for Series 1 which is what was used to plot the column charts (Really 1 chart)

Also note that I put data that is used for formatting on a separate worksheet from "Value Data". This makes it easier to maintain data as it needs to updated overtime



1. Horizontal gridlines

I am going to add fake horizontal gridlines to the chart, so first I'l remove the current horizontal gridlines.
  • Click on the chart (This will activate the Chart Tools Group on the Ribbon)
  • Click on "Layout" in the chart tools group
  • Click on gridlines
  • Click on Primary Horizontal Gridlines
  • Click on "None"



2. Add "Fake" horizontal gridlines

I copied all data from the formatting tab including the horizontal axis column, clicked on my chart and pasted the new series.

 I could click on each of the new series on the chart and change the chart type from column to line and apply all of the formatting. But I would like to do it with VBA. So I'll step through each part of the process separately
 

3. Change the chart type:

First I need to chage the chart type for each series that is not a value series which was series 1. So I'll loop through the SeriesCollection starting at number 2

1:  Option Explicit
2:  Sub SetChartType()
3:    Dim wb As Workbook
4:    Dim ws As Worksheet
5:    Dim i As Integer
6:    Set wb = ThisWorkbook
7:    Set ws = wb.Worksheets("Sheet1")
8:    With ws
9:      .ChartObjects(1).Activate
10:      For i = 2 To .ChartObjects(1).Chart.SeriesCollection.Count
11:        .ChartObjects(1).Chart.SeriesCollection(i).ChartType = xlLine
12:      Next i
13:    End With
14:    'Tidy up
15:      Set ws = Nothing
16:      Set wb = Nothing
17:  End Sub













4. Format the color of the lines

I would like each of the horizontal lines to be white

1:  Option Explicit
2:  Sub SetChartColor()
3:    Dim wb As Workbook
4:    Dim ws As Worksheet
5:    Dim i As Integer
6:    Dim lWhite As Long
7:    Set wb = ThisWorkbook
8:    Set ws = wb.Worksheets("Sheet1")
9:    lWhite = RGB(255, 255, 255)
10:    With ws
11:      .ChartObjects("Chart 1").Activate
12:      With ActiveChart
13:        For i = 2 To .SeriesCollection.Count
14:          .SeriesCollection(i).Select
15:          With Selection
16:            .Format.Line.ForeColor.RGB = lWhite
17:          End With
18:        Next i
19:      End With
20:    End With
21:    'Tidy up
22:      Set ws = Nothing
23:      Set wb = Nothing
24:  End Sub  













5. Change the line type:

The chart is looking pretty good. But the lines are a little thick, I would like something more subdued. I played around a bit with different line weights and dash styles until I found values that I liked

1:  Option Explicit
2:  Sub SetLineProperties()
3:    Dim wb As Workbook
4:    Dim ws As Worksheet
5:    Dim i As Integer
6:    Dim lWhite As Long
7:    Set wb = ThisWorkbook
8:    Set ws = wb.Worksheets("Chart")
9:    lWhite = RGB(255, 255, 255)
10:    With ws
11:      .ChartObjects("Chart 1").Activate
12:      With ActiveChart
13:        For i = 2 To .SeriesCollection.Count
14:          .SeriesCollection(i).Select
15:          With Selection
16:            .Format.Line.Weight = 1.5
17:            .Format.Line.DashStyle = msoLineRoundDot
18:          End With
19:        Next i
20:      End With
21:    End With
22:    'Tidy up
23:      Set ws = Nothing
24:      Set wb = Nothing
25:  End Sub  

I added the major horizontal gridlines back to the chart and made them very thin and light grey

The final chart:



The lines may be a little thin for your tastes, just adjust the line weight until you get the effect you are trying to achieve.

I hope you enjoy the post and that you find something of value in it.

Additional resources:
How do you use the SeriesCollection in your VBA or work with series in your charts? Let us know in the comments below.









Points Of Interest

0

Hello World! (Sorry, I could not resist J) I was recently asked by our host, Jordan, if I would be interested in being a guest author here at Option Explicit VBA. I quickly and humbly accepted. I will strive to do my best to add something of value. Let’s dive right in.

I was inspired the other day by Chandoo’s post on his blog in regards to tax burden as well as Jared’s subsequent submission regarding service levels. Both charts use a consistent color across what appears to be different series in panel charts that are arranged closely together.

In fact, they are not, the area charts are one series with blank rows or columns inserted in the data range to create the separated effect. Here is a sample initial column chart I created using the same concept






So far, so good - but I would like each "Series" to have a different color. I selected some data points and changed the fill color



Looking good, but I'll need to manually select an additional 22 data points and change the fill color for each point. It gets worse if I want to add additional, "Series" to the chart or decide to go back and change a color - more manual work!

So I thought to myself, "Self, there must be an easier way!" The good news is that there is an easier way through VBA! Let's cook up some code (Option Explicit VBA - Remember?)

I only have one ChartObject with one SeriesCollection, so that part is straight forward. But there are many points in the SeriesCollection to be considered. Additionally, I dont want to plot anyting or add color to anything for points 13 and 25 where I have blank rows in my data.

So, I want to do something with points 1-12, 14-25, 27-38. Sounds like a good candidate for a Select Case..Case..End Select structure.




Option Explicit
1: Sub ColorDataPoints()
2: Dim wb As Workbook
3: Dim ws As Worksheet
4: Dim i As Integer
5: Dim lBlue As Long
6: Dim lRed As Long
7: Dim lGreen As Long
8: Set wb = ThisWorkbook
9: Set ws = wb.Worksheets("Sheet2")
10: lBlue = RGB(79, 129, 189)
11: lRed = RGB(192, 0, 0)
12: lGreen = RGB(155, 187, 89)
13: With ws
14: For i = 1 To .ChartObjects(1).Chart.SeriesCollection(1).Points.Count
15: Select Case i
16: Case 1 To 12
17: .ChartObjects(1).Chart.SeriesCollection(1).Points(i).Interior.Color = lBlue
18: Case 14 To 25
19: .ChartObjects(1).Chart.SeriesCollection(1).Points(i).Interior.Color = lRed
20: Case 27 To 38
21: .ChartObjects(1).Chart.SeriesCollection(1).Points(i).Interior.Color = lGreen
22: End Select
23: Next i
24: End With
25: 'Tidy up
26: Set ws = Nothing
27: Set wb = Nothing
28: End Sub















Now I have a chart with one x-axis and what appears to be 3 different series, when in fact, it is one. Perhaps more importantly, I have a process that requires very little updating as my needs change to display more "Series" or to change colors.

More on the Points Collection.

Download the workbook .

How do you work with points in your charts and VBA? Let us know in the comments section.


Interactive Map in Excel using Rollovers

10
Alright, so this seemed like the next logical step for the rollover method:

Unable to display content. Adobe Flash is required.

This one is kinda complicated, I admit. Unfortunately, I didn't really take the time to clean up the spreadsheet file for others to follow (I don't really have the time these days). Sorry. But try to take it apart - and ask me questions if you have them.

I've canvassed some other folks from the Excel community to see if they would want to do a video tutorial of this - and I think that's what it would take.

Have fun!
Mapper.xlsm

Interactive Periodic Table of Elements in Excel

46
I've been on a real rollover kick lately. I'm really trying to figure out if it can be useful. Earlier today I started making a Periodic Table of Elements using Excel. I employed the rollover technique to allow the user to gain information about an element simply by rolling over a cell. Well, for some reason, I couldn't stop there. So what was meant to be a small project ballooned into something larger. Unfortunately, my sticking to good coding practice didn't keep up with craving to do more. So what I present to you below isn't really a polished product. If you poke through the named ranges and the rollover indexes, you'll probably see that I add and subtract one to them somewhat randomly (a cheap trick - this is  due to my trying to reconcile the table copied from Wikipedia with my indices).

As you can see below, you can not only gain information about an element but you can also toggle on and off different element groupings.

Unable to display content. Adobe Flash is required.

If you want to "crack" the file, the first thing you'll need to do is reset the ScrollArea (Click on a cell. Go to the Developer tab, click Properties. Delete the reference in the ScrollArea box.). Then just unhide everything.

Good luck.
Periodic Table.xlsm

Update -
Reader Dario found an error in the spreadsheet (see the comments) - this is the result of some carelessness and cheap tricks on my part. An updated version will be released tonight. In the meantime however, you can still poke around the file :).

Another Update -
I've since fixed the bug described in the reader comments. If you find anything else, let me know!

Miscellaneous Stuff

1
First, a big thank you to everyone following my blog. Here's some stuff I'd like to share in no particular order.

Stephen Colbert Come to My Wedding



We (my fiance and I) want Stephen Colbert to come to our wedding, which is in October of this year. My beautiful and wonderful fiance explains as follows:
During the tedious processes of inviting people to our wedding, my fiance and I began a running joke of inviting Stephen Colbert. Well, he may still be joking, but I'm not.
We don't have terminal illnesses or a terribly romantic love story--unless you consider our burning desire to have Stephen Colbert at our wedding an illness and online dating terribly romantic.







Want to help? Of course you do! Do this:
(1) Like us on Facebook.
(2) Follow us on twitter
(3) Get your friends to do the same!
Thanks in advance for the help, internet - you're so awesome!

* * *

Excel Custom Formats

Lately, I've really been into Excel custom formatting. This is my favorite page to reference when I have questions about custom formatting: http://www.ozgrid.com/Excel/CustomFormats.htm

Make to checkout all the other info ozgrid has to offer!

Looking for a cool Excel forum?

I am a contributor to the Excel forum, Excel Heros on LinkedIn. This forum is associated with the terrific Excel Hero website.

Visualization and You

I have a lot of strong feelings about visualizations as you may have noticed in a previous blog post. I believe that many organizations, including the media, software companies, and even universities are encouraging meaningless and distorted data representations.

The visualization guru, Stephen Few, has this excellent quiz to test your Graph Design IQ. Check it out!

Right now, I'm reading Few's book, Now you see it, which I highly recommend. A link for it will be up later on an "excel resources" page when it's complete.

Want to hire an Excel consultant, but don't know where to begin?

This page from Daily Dose of Excel is a good place to start.

Let's join forces!

As you may have noticed, sometimes my blog updates are sparse. I do this in my spare time and sometimes I'm just too busy to update. Part of the problem is I start writing tutorials that always become too big. For example, I wanted my sensitivity analysis tutorial to be complete in one post -- already, it might grow to three or four! I have a real problem.

Do you like writing? More specifically, do you like writing on Excel? Want to join forces? I would really love to have some more regular posts. Drop me a line if you're interested!

Have just one post you think you might want to share? Again, drop me a line!

I'd love to hear from you

Comment below, email, facebook, twitter, LinkedIn... whatever you want. Have something interesting? Share it!

Visualizing.org: Garbage In, Garbage Out

0
There are a lot of awful visualizations and info graphics floating around the internet. I've sent some of the worst I've found to my new internet friend, Kaiser Fung, at JunkCharts. His blog hosts a formidable, if unfortunate, collection of chartjunk and he attempts both to make sense of them as well as to provide suggestions on how to make them better. 

So where do I find these graphics?  I go to Visualizing.org, a site I am finding harder to respect as time goes on.  That might sound harsh, but if the aim of the site is to "make sense of complex issues," I think they often miss this point while giving praise and monetary rewards to data designs that, in fact, make issues harder to understand.  To demonstrate this point consider a recent winning visualization, E-CUBE-LIBRIUM, from a team at Columbia University.  According to the team: 
By configuring social, economic, and environmental data in terms of a "Rubik's Cube" analogy, the cube represents a country's growth with inversely proportional categories placed opposite each other. The 3D extrusions on each cube face is a sustainability indicator, showing volumes where data increases or decreases. From these models, we are able to quickly draw connections and visually identify how each factor affect the equilibrium of the entire system....For example, how do economic gains adversely affect social and environmental health? In each cube, we are searching for stable equilibrium and positive, balanced development that can be sustained over time. Unstable equilibrium may appear to be balanced, but it is not sustainable, due to an irresponsible levels of CO2 emissions, or alarming income and social disparity, for example.
Here's how the country of Chad is represented in the Rubik's cube analogy:


In theory, plotting a country's relevant indicators should give some visual cues and insights. However, their three-dimensional forms obscure much of this data. There is no scale and no way to tell while looking at each figure if a system is balanced, or even how much gain is too much gain. Moreover, so much is represented that we must keep deferring to the legend to figure out exactly what we're looking at.

But there are larger problems that seriously undermine the team's work.  First, this paragraph I excerpted from their write up:
By abstracting data into these virtual objects, they can then be tested for physical properties such as center of gravity, balance point, mass, inertia, aerodynamics, and any number of precise simulation results...The center of gravity of a cube gives us indications as to where a country's development is distorted and which direction the country needs to move in order to achieve balance. Inertia allows us to test for direction of past and future movement - or lack thereof. Aerodynamics would reveal holes and outliers in a country's cube, indicative of a crisis or a boom/bust capitalist cycle.
I'm not sure what to say here except...no, these things aren't possible.  There's a reason we don't test a bar chart for its weight in pounds - or how far we can toss a three-dimensional pie chart like a Frisbee.  Graphs are representations of abstract values in made-up space; they don't have inherent physical properties.    

Which brings me to the second major problem.  Because humans are pattern-oriented, ideas that manifest symmetry and balance can be appealing and convenient.  Consider American politics: you might sit on the left, the right, or smack dab in the middle.  It's an arguably useful simplification; but when you consider where you fall on the political spectrum, is the "ideal" policy truly at the center point?  Put another way, what reason exists to assert that if a country's indicators aren't in "balance", or tending toward some abstract and invented equilibrium, national turmoil will result?  Nothing, of course.

But a steady rise in CO2 emissions sounds like sustainable growth, right?  Maybe, but E-CUBE-LIBRIUM never speaks to this point visually - it's a point asserted in the team's write up.  In fact, nothing new is gained by the visual Rubik's cube.  The actual country indicators by themselves, as numbers, likely do a better job of telling this story, if it exists.

Which brings me to the biggest problem of all: the entire thing is rather heavy-handed.  I believe the designers knew going in which countries they wanted to portray as "unsustainable." Consider,
Unstable equilibrium may appear to be balanced, but it is not sustainable, due to an irresponsible levels of CO2 emissions, or alarming income and social disparity, for example.
Because there's nothing in this visualization that indicates system imbalance, or, for that matter, irresponsible CO2 emissions or alarming social disparity, I’m left wondering if these items aren't just the preconceived notions the designers imposed upon their visualization.  Indeed, the passage appears to argue that their design could give a misleading impression about a country’s stability, that knowledge of a country not presented here (such as social disparity) might mean the appearance of sustainability is incorrect.  Put another way, it doesn't matter what our visualization says, it can't be sustainable because we can't have a country that pollutes at an alarming rate violate our ridiculous analogy. Sounds like confirmation bias to me.  

Apparently, Visualizing.org, Columbia University, and the United Nations disagrees with me (and, to some extent, Newtonian Physics). This team's nonsense won their school $10,000 to continue visualization education.  Hopefully, Columbia will invest in some books on the subject


I'll leave you with this.