vangog
10-12-2022, 01:53 PM
Let's suppose that in sheet "t" where a table is located... In sheet "Charts" I have charts. I have selected the Sheet "Charts" and now I need to access the table in Charts, iterate through and set the styles in charts in ActiveSheet ("Charts").
So I have written this code (intended for old Excel).
Dim wsS As Worksheet, it As ChartObject, table As Range, c As Integer, l As Integer
Set wsS = Sheets("t")
Set table = wsS.Range("A1", Range("D11"))
For l = 1 To table.Rows.Count
For Each it In ActiveSheet.ChartObjects
it.Chart.SeriesCollection(l).Fill.ForeColor = table.Rows(l).Columns.Cells(1).Value
it.Chart.SeriesCollection(l).MarkerStyle = table.Rows(l).Columns.Cells(2).Value
it.Chart.SeriesCollection(l).MarkerSize = table.Rows(l).Columns.Cells(3).Value
it.Chart.SeriesCollection(l).MarkerForegroundColor = table.Rows(l).Columns.Cells(4).Value
Next it
Next
Now I have error 1004 Method Range of obj. Worksheet failed.
How to correct the range method?
So I have written this code (intended for old Excel).
Dim wsS As Worksheet, it As ChartObject, table As Range, c As Integer, l As Integer
Set wsS = Sheets("t")
Set table = wsS.Range("A1", Range("D11"))
For l = 1 To table.Rows.Count
For Each it In ActiveSheet.ChartObjects
it.Chart.SeriesCollection(l).Fill.ForeColor = table.Rows(l).Columns.Cells(1).Value
it.Chart.SeriesCollection(l).MarkerStyle = table.Rows(l).Columns.Cells(2).Value
it.Chart.SeriesCollection(l).MarkerSize = table.Rows(l).Columns.Cells(3).Value
it.Chart.SeriesCollection(l).MarkerForegroundColor = table.Rows(l).Columns.Cells(4).Value
Next it
Next
Now I have error 1004 Method Range of obj. Worksheet failed.
How to correct the range method?