0

I've looked around at Stackoverflow and other websites, but I haven't found the solution to the following:

I would like to set the data for a chart manually in VBA. I do not want a reference to a worksheet, e.g.

MyChart.SeriesCollection(1).XValues = "=Sheet1!$F$25:$G$25"

What I want is something like:

MyChart.SeriesCollection(1).XValues = {Value1,Value2,Value3,...}

But I have no clue how to set the data this way. Any help is much appreciated!

1 Answer 1

3

Do this with an array of values:

Dim xVals() As Variant

xVals = Array(30,50,70,90,25)


MyChart.SeriesCollection(1).XValues = xVals

If you want to use the values from the sheet, without a reference to the sheet, you could modify it slightly. Using this method, we can take the values from the worksheet, store them in an array and use the array to populate the chart data. The chart will then reflect the data, but it will not update as the data changes, so you could use this method to prevent users from inadvertently changing a chart's data:

Dim xVals() As Variant
xVals = Sheet1.Range("F25:G25").Value
MyChart.SeriesCollection(1).xValues = xVals
Sign up to request clarification or add additional context in comments.

1 Comment

Works :) I was looking for this the past 30 minutes... Thanks David! (Can't accept your answer yet, must wait 12 minutes)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.