+ Reply to Thread
Results 1 to 3 of 3

Calling on a sub that generates a chart using ARRAY values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Calling on a sub that generates a chart using ARRAY values

    So, I have created an array, and I am trying to put the data into a chart... but I have no clue how to make the chart take on the data from an array I generated, rather than from a range. I coded for a chart uding a Range from an excel sheet.. but I can't see how to make all of that happen when I have this array..

    I have two sub procedures. Inside one of them I want to use

    Call ChartNew2(myArray)
    And I will be calling on:

    Sub ChartNew2()
        Charts.Add
            ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
            ActiveChart.SetSourceData Source:=Range("D1:D30"), PlotBy:=xlColumns
            ActiveChart.Location Where:=xlLocationAsObject
            
            With ActiveChart
                        .HasTitle = True
                       
                        .Axes(xlValue, xlPrimary).HasTitle = True
                    
            End With
    
            With ActiveChart.Axes(xlValue)
                        .HasMajorGridlines = True
            End With
    
            ActiveChart.HasLegend = False
            ActiveChart.PlotArea.Select
    
            Selection.Interior.ColorIndex = xlAutomatic
            ActiveChart.Axes(xlValue).Select
    
            With ActiveChart.Axes(xlValue)
    
                    .MaximumScale = 1
    
            End With
    
        End Sub
    How can I do that? I tried in this way and I wasn't successful either...

    Sub ChartNew2(result2 As Variant)
        Dim i As Integer
        ReDim result2(1 To 4, 1 To 1)
        Charts.Add
            For i = LBound(result2, 1) To UBound(result2, 1)
                result2(i, 1) = result2
            Next i
            ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
            ActiveChart.Location Where:=xlLocationAsObject
    
    
          'For i = 1 To 4
             '   With ActiveChart.SeriesCollection(1)
              '          .XValues = result2(i)
               '         .Values = arrIntervals(i)
                'End With
            'Next i
            
            With ActiveChart
                        .HasTitle = True
                        .Axes(xlValue, xlPrimary).HasTitle = True
                End With
      
                      
            With ActiveChart.Axes(xlValue)
                        .HasMajorGridlines = True
            End With
    
            ActiveChart.HasLegend = False
            ActiveChart.PlotArea.Select
    
            Selection.Interior.ColorIndex = xlAutomatic
            ActiveChart.Axes(xlValue).Select
    
            With ActiveChart.Axes(xlValue)
    
                    .MaximumScale = 1
    
            End With
    
        End Sub
    Last edited by seigna; 04-26-2013 at 02:41 AM. Reason: I did a few trials..

  2. #2
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Re: Calling on a sub that generates a chart using ARRAY values

    Btw, it's supposed to be a LINE chart/graph

  3. #3
    Forum Contributor
    Join Date
    04-07-2013
    Location
    France
    MS-Off Ver
    Excel 2011
    Posts
    166

    Re: Calling on a sub that generates a chart using ARRAY values

    The second code above generates a blank page and I get a message: "Invalid parameter".

+ 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.6.0 RC 1