Adding a Datapoint Table to Excel with VBA

I have a 3 row chart object. The series receives Y values ​​from the ranges C1: C10, D1: D10 and E1: E10. The value depends on the values ​​in A1: A10 (for example, C1 = A1 + 6); but I am drawing values ​​with values ​​in B1: 10 (his graph is Log-Normal).

I am calculating values ​​in VBA. Since there is only a discrete number of points in A1: A10, I would like to add some additional points of interest in the diagram. Therefore, if A1: A10 contains integers from 1 to 10, I would like to construct a decimal number, for example, 3.5, without adding any new lines to the worksheet.

From a look around, I would suggest that it will be something with the Extend Method ( MSDN - Extend Method ), but I'm not sure how:

  • Extend a specific series (for example, add only a point to lines C1: C10 and D1: D10
  • How to add a data point without requiring adding a cell to the worksheet.

Any help would be greatly appreciated. Thanks

+3
source share
1 answer

Question 2

You can set values ​​in a separate series using the value property of the series object.

However, the help states that the values ​​in the series may be

range on a sheet or an array of constant values,

but not both.

This means that if you want to specify the values ​​of a series as a range, such as C1: C10, then I think you will need to add cells if you want to add data points to the series.

If you do not want to add a cell, you need to specify all values ​​as an array constant.

1

, , XValues ​​.

:

"1" Excel "Chart1". y1 1, y2 2, y3 3.

     A    B     C     D
1    x    y1    y2    y3
2    1    10    100   400
3    2    20    200   500
4    3    30    300   600

y2.

     A    B     C     D
1    x    y1    y2    y3
2    1    10    100   400
3    2    20    200   500
4    3    30    300   600
5    4          1000

( 2 "y2" ) Value "C2: C5"

'using ranges
Charts("chart1").SeriesCollection("y2").Values = Worksheets("Sheet1").Range("C2:C5")

'using array constant
Charts("chart1").SeriesCollection("y2").Values = Array(100, 200, 300, 1000)

XValues, XValue

'using ranges
Charts("chart1").SeriesCollection("y2").XValues = Worksheets("Sheet1").Range("A2:A5")

'using array constant
Charts("chart1").SeriesCollection("y2").XValues = Array(1, 2, 3, 4)

:

XValues ​​ .

, Valal .

.

XValues ​​ .

+4

Source: https://habr.com/ru/post/1718253/


All Articles