Question : How do I programmatically change source data range using Excel VBA?

How do I programmatically change source data range using Excel VBA?

What is a sample script?

Thanks

Answer : How do I programmatically change source data range using Excel VBA?

Hi kosenrufu,

the best way is to ask your Excel! :)
Start macro recording, select your graph and perform needed actions. Then stop recording and see result.
You'll get something like

    ActiveChart.SeriesCollection(1).Name = "='Sheet1'!$B$1"
    ActiveChart.SeriesCollection(1).Values = "='Sheet1'!$B$2:$B$3"
    ActiveChart.SeriesCollection(1).XValues = "='Sheet1'!$A$1:$A$3"

You may assign a range directly without manipulating strings, i.e.

ActiveChart.SeriesCollection(1).Values = MyRange

Alex
Random Solutions  
 
programming4us programming4us