+ Reply to Thread
Results 1 to 5 of 5

Add high/low points to a line chart

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2012
    Location
    Utah, USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Add high/low points to a line chart

    I am trying to figure out how to add high/low points to a line graph, similar to what sparklines have. The file I am using now doesn't allow me to add new columns of data, so I'm trying to figure something out that just updates dynamically using the data I already have in place.

    This page has the thing I want to do, but it requires additional columns to be added to work, which I don't want:

    http://excelmate.tumblr.com/post/259...n-a-line-chart

    Any thoughts on how this can be done? I'd appreciate any help.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Add high/low points to a line chart

    You can use dynamic named ranges for a series of hi/lo points.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-27-2012
    Location
    Utah, USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Add high/low points to a line chart

    Thanks for the reply, I didn't even know that kind of thing was possible. And if I didn't have so many tabs to work with that would be my preferred option. Instead I've figured out how to add the high/low points pretty easily with VBA, which I've included in the data update routine. Here's the code if anyone is interested:

    Sub HighLowPoints()
    Dim ws As Worksheet
    Dim p As Point
    Dim vMin As Variant
    Dim vMax As Variant
    Dim pMin As Variant
    Dim pMax As Variant
    Dim sh As Shape
    Dim v As Variant
    Dim i As Integer
    
    'Goes through all my sheets in the current workbook
    For Each ws In ActiveWorkbook.Worksheets
        'If it finds a sheet that I want it to work in...
        Select Case ws.Name
        Case "EUR", "GC", "LAM", "NAM", "NEA", "SEA"
            'Then it goes through the shapes until it finds one with a name that I've decided needs to be worked on...
            For Each sh In ActiveSheet.Shapes
                If sh.Name = "DistrTrend" Or sh.Name = "PCTrend" Then
                    'Then it takes all the SeriesCollection values and puts them into a variable, and finds the max/min values in that array.
                    v = sh.Chart.SeriesCollection(1).Values
                    vMin = Application.WorksheetFunction.Min(v)
                    vMax = Application.WorksheetFunction.Max(v)
                    pMin = Application.WorksheetFunction.Match(vMin, v, 0)
                    pMax = Application.WorksheetFunction.Match(vMax, v, 0)
                    'Then goes through all the values in the line chart, and if a point is equal to the already determined min/max value it adds a point there, the same size as a sparkline point.
                    For Each p In sh.Chart.SeriesCollection(1).Points
                        i = Right(p.Name, Len(p.Name) - 3)
                        Select Case i
                        Case pMin, pMax
                            p.MarkerBackgroundColorIndex = 1
                            p.MarkerForegroundColorIndex = 1
                            p.MarkerStyle = 2
                            p.MarkerSize = 2
                        End Select
                    Next p
                End If
            Next sh
        End Select
    Next ws
    End Sub

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Add high/low points to a line chart

    Does your code handle multiple min or max data points?

    What's the reason for not using cells/formula ?

  5. #5
    Registered User
    Join Date
    08-27-2012
    Location
    Utah, USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Add high/low points to a line chart

    It doesn't handle multiple as it is, but it seems to be handling multiples when I change this
    For Each p In sh.Chart.SeriesCollection(1).Points
    i = Right(p.Name, Len(p.Name) - 3)
    Select Case i
    Case pMin, pMax
        p.MarkerBackgroundColorIndex = 1
        p.MarkerForegroundColorIndex = 1
        p.MarkerStyle = 2
        p.MarkerSize = 2
    End Select
    to this

    i = 0
    For Each val In sh.Chart.SeriesCollection(1).Values
        i = i + 1
        Select Case val
        Case vMin, vMax
            sh.Chart.SeriesCollection(1).Points(i).MarkerBackgroundColorIndex = 1
            sh.Chart.SeriesCollection(1).Points(i).MarkerForegroundColorIndex = 1
            sh.Chart.SeriesCollection(1).Points(i).MarkerStyle = 2
            sh.Chart.SeriesCollection(1).Points(i).MarkerSize = 2
        Case Else
            sh.Chart.SeriesCollection(1).Points(i).MarkerBackgroundColorIndex = xlNone
            sh.Chart.SeriesCollection(1).Points(i).MarkerForegroundColorIndex = xlNone
            sh.Chart.SeriesCollection(1).Points(i).MarkerStyle = xlNone
        End Select
    Next val

    And the reason I don't want to use the cells formula is that I have a nice/clean setup as is, and I don't want to make my spreadsheets any more messy than they are. I don't want to do the dynamic range thing because I have a ton of tabs and I'd have to make separate named ranges for each tab, and that would also get messy. Since I already need to run some code to update each tab, I figured it would be easiest to just slip the code in at the end.

    Thanks for your feedback!

+ 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. Replies: 3
    Last Post: 04-07-2013, 07:40 AM
  2. Line Chart points properties
    By ElmerS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2010, 02:40 AM
  3. Accessing Points in a Line Chart
    By Techno_Dex in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-11-2006, 07:05 PM
  4. Replies: 0
    Last Post: 02-08-2006, 05:15 PM
  5. Null points in a line chart
    By rmellison in forum Excel General
    Replies: 1
    Last Post: 09-06-2005, 09:05 PM

Tags for this Thread

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