Home arrow Blog arrow Adding a horizontal line to the top of an Excel Line Chart...
Friday, 24 February 2017
Main Menu
Web Links
Blog Links
Musical Links
Nerdery Links
Other Neato Links
Adding a horizontal line to the top of an Excel Line Chart...
User Rating: / 2
Written by WATYF on Friday, 28 March 2008 (7922 hits)
Category: Nerdery

I've run into this problem before and always ended up falling back on crappy work-arounds, but it came up again the other day, so I figured I'd find a suitable solution once and for all. Here's the problem... I have a line chart in Excel... I want to display data going upwards and across the chart (like a typical line chart), but across the top of the chart, I want to display a horizontal line that shows a "target" (a single value in a single cell somewhere) that I'm trying to reach. There are several ways to approach this, but none of them I had found up to this point were elegant and/or sufficient for my needs...

One of the possible solutions (and the one I was previously using) was quite simple... take your single value and duplicate it however many times it takes to cover the whole chart. So, let's say you have a line chart showing the growing sales throughout a 20 day period... like so:













Well... if you only have a target value in one cell, that value is only going to show up at the top of one data point (Day 1)... but if you copy it over a range of 20 cells and use that 20 cells as a Series in the chart, voila... you have your line. But what if you don't want a random range of 20 cells strewn across your spreadsheet? And in my case, I have two lines, so that means I'd need two sets of 20 cell ranges, all displaying the same value over and over. Sure I could put them on another sheet and hide it and all that, but where's the fun in that?

Other solutions involve things like drawing a line using the Drawing tools (not very handy if your target changes often), or commandeering the Secondary X axis (a Google search will find many such suggestions)... the problem with that one is, again... it's inelegant, but not only that, its fatal flaw is that it's limited to only one horizontal line (since there is only one Secondary X axis), and since my chart requires two horizontal lines (one target for each of the two lines), that just won't do.

Finally, I stumbled on something that lead me to a solution that was just what I was looking for: Using a named range to "project" the same value over an "imaginary" range.

It goes like this... let's say that the value I want to put across the top of the chart is in cell B50. So, working with our "20 days" chart, we need to take the value in B50 and spread it out across a range of 20 cells without actually physically copying it over 20 cells and using up all that space... we just want the chart to think that the value is 20 cells long. Well, we do this by creating a named range (Insert > Name > Define), and instead of just putting a reference to a cell (B50) in the named range, we put this formula:


This does two things... first, it references the value you're looking for (B50)... second, it takes that value and "extends" it using the dimensions of a range of cells (A1:A20). Now... the range you use has to be the same amount of cells as your data points... so, for my "20 days" chart, the range is 20 cells. The thing is, it really doesn't matter what range you put in there (A1:A20 or B30:B50 or Z11:Z33), just so long as it's 20 cells (or however many cells as there are data points). The range you use (A1:A20) doesn't get written to or referenced, so it doesn't matter what data is in A1:A20, because that actual range itself isn't being used, just its dimensions. So, once I create named ranges called "Target1" and "Target2", I can add those named ranges as Series in my chart and I get this...














Problem solved.



Next >


You must javascript enabled to use this form

Have you attempted using a dynamic named range instead of a named range so that your line automatically extends with new data entries. (Instead of having to update your named ranges)

Posted by Stephen, on 03/18/2009 at 11:16

Page 1 of 1 ( 1 Comments )
©2007 MosCom

TaskRunner Spam-a-lot

It's cool. It's nifty. It does stuff. It's...

  TaskRunner 3.2!!

Click here to get the brand spanking new version of TaskRunner... 3.2!!
Who's Online

Recent Posts
Most Popular
© 2017 Musical Nerdery
Joomla! is Free Software released under the GNU/GPL License.