Error occuring when trying to produce graph from other sheet vba

JakeK

I have a set of code, that sometimes produces an error.

What the code does
The code takes a fixed range of values from another spreadsheet. Those values are then simply used to create a scatter graph. And the graph gets pasted onto the current worksheet.

The Error Message

The error box I am getting

The code is a Run-time error '-2147221504 (80040000)': The maximum number of data series per chart is 255.

Again, this error only sometimes gets produced.

The Code

    Dim GraphRange As Range
    Dim cht As Shape

    Set GraphRange = Sheets("This Sheet").Range("V10:W8013")
    Set cht = Sheets("This Sheet").Shapes.AddChart2(, xlXYScatterSmoothNoMarkers)

    With cht.Chart
        .SetSourceData Source:=GraphRange
        .FullSeriesCollection(1).Format.Line.Weight = 1.5
        .ChartArea.Height = 520
        .ChartArea.Width = 400
        .Axes(xlCategory).ReversePlotOrder = True
        .ChartTitle.Text = "The Graph"

    End With

The Code is called from another sub, however, I do not think the conditions in which it is called is the problem.

EDIT
When this error occurs, for whatever reason, it is trying to take the values from the sheet that it is supposed to be pasting the graph on. Meaning it isn't even looking at the correct spreadsheet.

JakeK

This has been working for me so far... I PlotBy:=xlColumns in .SetSourceData

Sub CreateGraph()

Dim GraphRange As Range
Dim cht As Shape

Set GraphRange = Sheets("This Sheet").Range("V10:W8013")
Set cht = Sheets("This Sheet").Shapes.AddChart2(, xlXYScatterSmoothNoMarkers)

    With cht.Chart
        .SetSourceData Source:=GraphRange, PlotBy:=xlColumns
        .SeriesCollection(1).Format.Line.Weight = 1.5
        .ChartArea.Height = 520
        .ChartArea.Width = 400
        .Axes(xlCategory).ReversePlotOrder = True
        .ChartTitle.Text = "My Graph"

    End With
End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error when trying to get an int from textbox

From Dev

Inserting a Column from One Sheet to the Other Sheet

From Dev

VBA Getting an error when trying to move a chart

From Dev

Exception self suppression error in try-with-resources not occuring from Eclipse

From Dev

Insufficient privileges error when trying to access Azure Graph APIs

From Dev

Type Mismatch 13 error when trying to activate a sheet

From Dev

VBA Runtime error 1004 when trying to access range of sheet

From Dev

Error when trying to remove an struct from a vector

From Dev

How to use VLOOKUP and get details from other sheet using VBA

From Dev

How to handle Exception occuring when returning StreamingResponseBody from RestController

From Dev

Stackoverflow error occuring when converting Object list to Json string

From Dev

"MailboxNotHostedInExchangeOnline" when trying to get user photos from MS Graph

From Dev

StorageException occuring when trying to get image from firebase database into storage

From Dev

Error when trying to retrieve from database

From Dev

Dojo Library loading error in Worklight project when trying to access from other Machine

From Dev

Powershell - Hide error message from displaying, occuring on line 3

From Dev

Run-time error 13: Type Mismatch in VBA when trying to call function from another workbook

From Dev

mySql Column not found error occuring from servlet

From Dev

VBA Run-time error 1004 when trying to copy paste cells in a separate sheet

From Dev

Django ManyToManyField error when trying to pull values from other models

From Dev

How to use VLOOKUP and get details from other sheet using VBA

From Dev

error occuring when running custom Google map application

From Dev

Unable to copy entire row from one sheet to the other with VBA

From Dev

Runtime error when trying to find components in a graph

From Dev

Trying to Concatenate from another sheet on VBA

From Dev

Python gives me an error when trying to get anything other than first or last two elements from list

From Dev

Nodejs Smartsheet API Error when trying to move row to another sheet

From Dev

VBA Excel return value from other sheet

From Dev

EOFError: EOF when reading a line. What is this Error and why is it occuring?

Related Related

  1. 1

    Error when trying to get an int from textbox

  2. 2

    Inserting a Column from One Sheet to the Other Sheet

  3. 3

    VBA Getting an error when trying to move a chart

  4. 4

    Exception self suppression error in try-with-resources not occuring from Eclipse

  5. 5

    Insufficient privileges error when trying to access Azure Graph APIs

  6. 6

    Type Mismatch 13 error when trying to activate a sheet

  7. 7

    VBA Runtime error 1004 when trying to access range of sheet

  8. 8

    Error when trying to remove an struct from a vector

  9. 9

    How to use VLOOKUP and get details from other sheet using VBA

  10. 10

    How to handle Exception occuring when returning StreamingResponseBody from RestController

  11. 11

    Stackoverflow error occuring when converting Object list to Json string

  12. 12

    "MailboxNotHostedInExchangeOnline" when trying to get user photos from MS Graph

  13. 13

    StorageException occuring when trying to get image from firebase database into storage

  14. 14

    Error when trying to retrieve from database

  15. 15

    Dojo Library loading error in Worklight project when trying to access from other Machine

  16. 16

    Powershell - Hide error message from displaying, occuring on line 3

  17. 17

    Run-time error 13: Type Mismatch in VBA when trying to call function from another workbook

  18. 18

    mySql Column not found error occuring from servlet

  19. 19

    VBA Run-time error 1004 when trying to copy paste cells in a separate sheet

  20. 20

    Django ManyToManyField error when trying to pull values from other models

  21. 21

    How to use VLOOKUP and get details from other sheet using VBA

  22. 22

    error occuring when running custom Google map application

  23. 23

    Unable to copy entire row from one sheet to the other with VBA

  24. 24

    Runtime error when trying to find components in a graph

  25. 25

    Trying to Concatenate from another sheet on VBA

  26. 26

    Python gives me an error when trying to get anything other than first or last two elements from list

  27. 27

    Nodejs Smartsheet API Error when trying to move row to another sheet

  28. 28

    VBA Excel return value from other sheet

  29. 29

    EOFError: EOF when reading a line. What is this Error and why is it occuring?

HotTag

Archive