+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Forum Contributor
    Join Date
    10-01-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2003
    Posts
    122

    drawing lines on a column graph

    hello there,

    here is what I am trying to achieve:

    modifiy the macro of the attached file so that it will draw lines on the graphs and end up ressembling the imge I attach as well

    (thee segments connecting the two columns)

    on top of the horizontal line I'd like to put the contents of a cell

    is that feasible or better start drawing the lines myself?

    ps. you need to create a sheet called graphs for the macro to run
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: drawing lines on a column graph

    You can use additional xy-scatter series to draw lines on a chart.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    10-01-2009
    Location
    Barcelona
    MS-Off Ver
    Excel 2003
    Posts
    122

    Re: drawing lines on a column graph

    wow, this looks quite promising --

    can you give me some guidance on how to code that on VBA?

    the values of the scatterline I guess I can work them out, but I do not know quite the commands

    also how did you manage to have all the bars sticked together?

    thanks a lot

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: drawing lines on a column graph

    The bars are stuck together by setting,
    Overlap = 100%
    Gap Width = 0%

    As to coding you just need to add a new series, ax xy-scatter, specifying the range used for x and y values.

    Code:
    Sub AddLines()
    
        Dim rngXValues As Range
        Dim rngYValues As Range
        
        Set rngXValues = Range("R3:R7")
        Set rngYValues = Range("S3:S7")
        
        With ActiveSheet.ChartObjects(1).Chart
            With .SeriesCollection.NewSeries
                .ChartType = xlXYScatterLinesNoMarkers
                .Values = rngYValues
                .XValues = rngXValues
            End With
        End With
    End Sub
    Cheers
    Andy
    www.andypope.info

Thread Information

Users Browsing this Thread

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

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.2.0