+ Reply to Thread
Results 1 to 4 of 4

Thread: Creating more than one graph (chart) on a worksheet

  1. #1
    Registered User
    Join Date
    09-06-2010
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    3

    Question Creating more than one graph (chart) on a worksheet

    Hi,

    I have a spreadsheet of store sales, costs and average sales. The data for each store is contained within a single tab, so I have 3 tabs for 3 stores.

    I need to be able to create two graphs on each tab. The first graph containing sales and average sales, and the second graph containing costs and average sales.

    I recorded a macro, which works fine for creating the first graph. But when I copy the code and add it too the end (and change the series to the cost data), I get errors.

    I would also like to be able to position these graphs. Graph 1 - cells A34 to F50 and Graph 2 - cells H34 - O50.

    Of course I will need to rerun this code for the remaining stores as well.

  2. #2
    Forum Guru
    Join Date
    10-28-2008
    Location
    Not here anymore
    MS-Off Ver
    irrelevant
    Posts
    10,150

    Re: Creating more than one graph (chart) on a worksheet

    Hi AnnieNZ,

    please post a sample workbook with dummy data that represents your data structure and include the code you have so far.

    cheers

  3. #3
    Registered User
    Join Date
    09-06-2010
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Creating more than one graph (chart) on a worksheet

    Hi Teylyn,

    Will do so in a few hours. My security would not allow me to upload the file.

    I have managed to fix the problem of creating two graphs on same worksheet. But they open on top of each other, not side by side.

    Cheers

  4. #4
    Registered User
    Join Date
    09-06-2010
    Location
    Auckland, New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Creating more than one graph (chart) on a worksheet

    Here is the spreadsheet of sample data, and the code I am using:

    I need to have graph 1 start at A34 through to F50, and graph 2 start H34 through to O50.

    I also need to repeat for the remaining two tabs (in reality I have 60 tabs, so really need this to be automated)

    Sub CreateMulitpleCharts()
    
    'Sales chart
        Charts.Add
        ActiveChart.ChartType = xlLineMarkers
        ActiveChart.SetSourceData Source:=Sheets("Store260").Range("A9")
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(1).XValues = "=Store260!R2C2:R2C13"
        ActiveChart.SeriesCollection(1).Values = "=Store260!R3C2:R3C13"
        ActiveChart.SeriesCollection(1).Name = "=Store260!R3C1"
        ActiveChart.SeriesCollection(2).XValues = "=Store260!R2C2:R2C13"
        ActiveChart.SeriesCollection(2).Values = "=Store260!R6C2:R6C13"
        ActiveChart.SeriesCollection(2).Name = "=Store260!R6C1"
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Store260"
        With ActiveChart
            .HasTitle = True
            .ChartTitle.Characters.Text = "Store 260 Sales"
            .Axes(xlCategory, xlPrimary).HasTitle = False
            .Axes(xlValue, xlPrimary).HasTitle = False
        End With
        ActiveChart.PlotArea.Select
        With Selection.Border
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With Selection.Interior
            .ColorIndex = 2
            .PatternColorIndex = 1
            .Pattern = xlSolid
        End With
        
     'Costs chart
        Charts.Add
        ActiveChart.ChartType = xlLineMarkers
        ActiveChart.SetSourceData Source:=Sheets("Store260").Range("A9")
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(1).XValues = "=Store260!R2C2:R2C13"
        ActiveChart.SeriesCollection(1).Values = "=Store260!R4C2:R4C13"
        ActiveChart.SeriesCollection(1).Name = "=Store260!R4C1"
        ActiveChart.SeriesCollection(2).XValues = "=Store260!R2C2:R2C13"
        ActiveChart.SeriesCollection(2).Values = "=Store260!R6C2:R6C13"
        ActiveChart.SeriesCollection(2).Name = "=Store260!R6C1"
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Store260"
        With ActiveChart
            .HasTitle = True
            .ChartTitle.Characters.Text = "Store 260 Costs"
            .Axes(xlCategory, xlPrimary).HasTitle = False
            .Axes(xlValue, xlPrimary).HasTitle = False
        End With
        ActiveChart.PlotArea.Select
        With Selection.Border
            .Weight = xlThin
            .LineStyle = xlNone
        End With
        With Selection.Interior
            .ColorIndex = 2
            .PatternColorIndex = 1
            .Pattern = xlSolid
        End With
        
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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