J
jay dean
I am trying to update the source of data of many charts on sheet
"Charts" with the code below. It seems to work fine EXCEPT THAT all the
charts below the first one take their source of data from the first one
instead of data from themselves because each chart has its own data. I
guess "rng" below does not go through all the other charts as I expect.
Any help would be appreciated.
Dim ocht As ChartObject
Dim cht As Chart
Dim dir As Variant
Dim rng As Range
For Each ocht In ActiveSheet.ChartObjects
For Each dir In Range("A:A")
If dir.Interior.ColorIndex = 55 Then
Set rng = Range(Cells(dir.Row, 1), Cells(dir.Offset(3).Row, 31))
Set cht = ocht.Chart
ActiveSheet.ChartObjects(ocht.Name).Activate
ActiveChart.PlotArea.Select
ActiveChart.SetSourceData Source:=Sheets("Charts").Range(rng.Address),
PlotBy:=xlRows
ActiveWindow.Visible = False
Exit For
End If
Next
Next
End Sub
Thanks.
Jay Dean
"Charts" with the code below. It seems to work fine EXCEPT THAT all the
charts below the first one take their source of data from the first one
instead of data from themselves because each chart has its own data. I
guess "rng" below does not go through all the other charts as I expect.
Any help would be appreciated.
Dim ocht As ChartObject
Dim cht As Chart
Dim dir As Variant
Dim rng As Range
For Each ocht In ActiveSheet.ChartObjects
For Each dir In Range("A:A")
If dir.Interior.ColorIndex = 55 Then
Set rng = Range(Cells(dir.Row, 1), Cells(dir.Offset(3).Row, 31))
Set cht = ocht.Chart
ActiveSheet.ChartObjects(ocht.Name).Activate
ActiveChart.PlotArea.Select
ActiveChart.SetSourceData Source:=Sheets("Charts").Range(rng.Address),
PlotBy:=xlRows
ActiveWindow.Visible = False
Exit For
End If
Next
Next
End Sub
Thanks.
Jay Dean