+ Reply to Thread
Results 1 to 13 of 13

How do I add horizontal line to a chart without adding a new series?

  1. #1
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    How do I add horizontal line to a chart without adding a new series?

    As it says, I have a workbook (actually a heap of workbooks) that has the first sheet with 31 charts on it. In the attached workbook there is 11 sheets of data. The first sheet with the charts has buttons to select which sheet (Piece of equipment) to look at. Some of these charts need horizontal lines on them. Some need upper and lower limits and others just an upper or lower limit. If I can work out how to do one of these I can do the rest. For example the the oil Viscosity @100 needs to be between 12.3 and 16.7.

    I am escpecting to have to do this unsing code so I have attached all the existing code below.

    Hope you can help like last time.

    First bit is the button sellect

    Please Login or Register  to view this content.
    This bit does all the charting. I have only included 2 pieces of equipment.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do I add horizontal line to a chart without adding a new series?

    How do you arrive at the 12.3 & 16.7?
    And what's wrong with using two extra series to plot them?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: How do I add horizontal line to a chart without adding a new series?

    I arrived at those figures as they were supplied by the testing agency as allowable limits for this equipment.

    Adding new series in my view would be too over complicated due the the number and variety of limits per chart/per sheet/per equipment.

    If you can show me a simple way to do this that ALSO automatically expands when more data is entered it would be greatly appreciated.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do I add horizontal line to a chart without adding a new series?

    Are you suggesting that the allowable limits for any PARTICULAR chart change with new data?
    In which case it seems to me that one way or another you need to know the rule the testing agency uses to come up with the limits.

    If the limits are not dynamic and not dependent on the a particular chart's data (and what's the point of having limits that do change just because the chart data changes) then it's somewhat easier since you can plot a series of constant values.

    Either way I can't see how you can plot the limits without a series unless you were to creat a horizontal line 'shape' and work out with a macro where the line should be placed. That would be somewhat complicated though.

  5. #5
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: How do I add horizontal line to a chart without adding a new series?

    Ok. Each piece of equipment may use a different viscosity oil which means that the allowable limits will be different. Each time you select a piece of equipment the chart changes to show the results that have been entered in the corresponding worksheet.

    If you have had a look at the file I attached you will see that the amount of data is different for each sheet. Some equipment is tested 3 monthly and other 2 yearly and others somewhere in between.

    I was hoping this would be a pretty simple task but I am begining to think I should posted it in the VBA section.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do I add horizontal line to a chart without adding a new series?

    Whatever the solution is though, surely it will involve plotting new chart series?

    Whether you do that with VBA or with Excel functions you'll need to derive the limits for each piece of equipment at the different temperatures.
    Take the two limits that vary with temperature. Presumably the limits for each of the Charts don;t change so can't you just add four extra rows of data, an upper an lower limit for each of the two temperatures and plot those series in the relevant chart.

  7. #7
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: How do I add horizontal line to a chart without adding a new series?

    I just had a bit of a fiddle (keep your minds out of the gutter) and and created something like what I am looking for. My question is now is how do I add a series to a chart without screwing up the existing chart?

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do I add horizontal line to a chart without adding a new series?

    Here's how you could add the upper / lower series. Take as an example the STBD Visc 100 chart

    Add a row of upper limits of 18 in each of the cells from B64:AG64
    Put the label STBD_V100_U in A64 i.e. the V100 is the viscosity and the 'U' refers to the Upper lImit
    Select A64:AG64 and create the name "STBD_V100_U" by using the Formulas....Name Manager...Create from selection using 'Left cell as the name choice'

    Then the macro for adding that upper line is

    Please Login or Register  to view this content.
    For the others you could follow that with similar blocks in the same procedure.
    Or better still put the a loop around the code after the first line and use variables to identify the Chart number, Series index number and the relevant range and let the loop add them

  9. #9
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: How do I add horizontal line to a chart without adding a new series?

    Worked a dream......except for a couple of small problems. The chart name/label disappeared and everytime I select that piece of equipment the line markers reappear after turning them off. The later is easy to fix I think.

  10. #10
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: How do I add horizontal line to a chart without adding a new series?

    Ok. Markers turned off and line colour set. I would like to get labels for the limit lines now but it doesn't work when I use

    Please Login or Register  to view this content.
    It comes up with an error, Unable to get count property of the Datalabels class.

  11. #11
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: How do I add horizontal line to a chart without adding a new series?

    I have found another problem with the code you supplied. Everytime I click on the button for Port MPDE it adds a new series. When I look "Select data" there is a heap of new series.

  12. #12
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do I add horizontal line to a chart without adding a new series?

    You'd need to trap that error with an IF statement. Look for the series name in the Names collection and if it exists don't proceed with the macro.

  13. #13
    Registered User
    Join Date
    11-29-2018
    Location
    Sunny Cairns, QLD AUST
    MS-Off Ver
    2010
    Posts
    97

    Re: How do I add horizontal line to a chart without adding a new series?

    Thanks for your suggestion but not needed. It appears that if I just click on the one button it will add extra series but if I click on a different button and then come back to the original all is good.

    I also solved the Chart title problem.

    I shall start a new thread for my next problem. I will probably put it in the VBA/code area as it might need some heavy thinking.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding Horizontal Line across Bar Chart and Label
    By jp16 in forum Excel Charting & Pivots
    Replies: 9
    Last Post: 10-13-2017, 06:38 AM
  2. Adding a horizontal Line to a Scatter Chart
    By Apple1 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 12-02-2014, 05:03 AM
  3. Adding horizontal line to VBA column chart
    By the_adam in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-04-2013, 09:56 AM
  4. Replies: 6
    Last Post: 11-26-2012, 05:17 AM
  5. Adding a horizontal line to a chart
    By Tinä in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-20-2011, 07:37 PM
  6. Adding a horizontal line to a chart that already has 2 axes?
    By Nakia6 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-27-2009, 02:04 PM
  7. Adding a horizontal line to a stock chart
    By wittmaennle in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-21-2006, 03:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1