This code puts a single point on my scatter plot. However the next 2 lines generate an error. How do you pass more than one X or Y value to the Set Data function in VBA?
These lines work:
Chart1_Series1.SetData OWC.ChartDimensionsEnum.chDimXValues, OWC.ChartSpecialDataSourcesEnum.chDataLiteral, (150)
Chart1_Series1.SetData OWC.ChartDimensionsEnum.chDimYValues, OWC.ChartSpecialDataSourcesEnum.chDataLiteral, (200)
These lines do not work: If I pass an array it give me an out of memory error.
Chart1_Series1.SetData OWC.ChartDimensionsEnum.chDimXValues, OWC.ChartSpecialDataSourcesEnum.chDataLiteral, (150,100)
Chart1_Series1.SetData OWC.ChartDimensionsEnum.chDimYValues, OWC.ChartSpecialDataSourcesEnum.chDataLiteral, (200,150)
Is this a continuation of your other post?
Did you see the KB link I posted?
I am learning more as I go so yes it is kind of a contiunuation although now I am stuck on a new trouble.
I read your KB post but I cannot find the exact same situation and I believe that is the root of my trouble. I find similar code but not exactly a scatter plot in VBA from arrays.
I am trying to make an XY Scatter plot via VBA Excel 2000, where the data is stored in 2 arrays, one for X values and one for Y values.
It seems as though the SetData method will only allow 1 data value. According to the MSDN website it says I should be able to pass a one dimentional string. But I cannot seem to get it done.
DataReference Optional Variant. For ChChart and ChSeries objects, this argument specifies the data reference as a Microsoft Excel-style range reference ("A1:D4" , for example), or a row-set column name. When the DataSourceIndex argument is set to chDataLiteral, you can set DataReference to a one-dimensional array or a comma-delimited list. For ChErrorBars objects, this argument specifies an array of Double or String values you can use for error-bar values. Note that you can use this argument only with custom error bars (the error-bar Type property must be set to chErrorBarTypeCustom).
Would the code not need to be
Or maybeCode:Chart1_Series1.SetData OWC.ChartDimensionsEnum.chDimXValues, OWC.ChartSpecialDataSourcesEnum.chDataLiteral, Array("150","100")
Code:Chart1_Series1.SetData OWC.ChartDimensionsEnum.chDimXValues, OWC.ChartSpecialDataSourcesEnum.chDataLiteral, "150,100"
I tired these and they give me an error.
The error is the "wrong number of arguments." which makes sense as everytime I try to send an array or a literal that is more than one value, it errors out.
I have seen numerous code samples on the net that show passing an array to the setdata function. How come it will not work in VBA?
Chris
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks