+ Reply to Thread
Results 1 to 2 of 2

Thread: Changing chart range - VBA

  1. #1
    Registered User
    Join Date
    10-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Exclamation Changing chart range - VBA

    Hi,

    Does anybody know how to change the source range of chart? Using VBA.

    For instace...

    Initially I have:
    Green Yellow Red Purple
    1 6 4 2
    2 5

    And I generate the chart:

    Sub Macro1()
    
        NbItems = Range("Sheet1!K7")
        NbPoints = Range("Sheet1!K8")
        Sheets("Sheet1").Activate
        
        Set rg1 = Range(Cells(1, 1), Cells(NbPoints + 1, NbItems + 1))
        rg1.Select
       
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlColumnStacked
        ActiveChart.PlotBy = xlColumns
        ActiveChart.ApplyDataLabels ShowSeriesName:=True, ShowValue:=False
       
    End Sub
    Later one, I have:
    Green Yellow Red Purple Pink
    1 6 4 2
    2 5 2

    How can I update the same chart? I.e., adding 2, Pink 2 to the existing chart (Using VBA).

    Any help is welcome. :-)
    Check the files.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by esther82; 10-30-2011 at 01:30 PM.

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

    Re: Changing chart range - VBA

    Sub AddNewData()
        
        Dim rngData As Range
        
        Set rngData = Range("F1")
        With ActiveSheet.ChartObjects(1)
            With .Chart.SeriesCollection.NewSeries
                .Name = rngData
                .Values = rngData.Offset(1, 0).Resize(2, 1)
            End With
        End With
    End Sub
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

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