I have four charts on a worksheet. Each chart has three series of data as in the source data (a separate worksheet for each chart). I need to have code that will look at the source data, create the four charts for a certain company, then go to the next row of data in each worksheet of source data and create four new charts, until the end of the data is reached (in this case, 183 companies).
I recorded a Macro to begin to see how the process would work, but when I try to replicate the code from the Macro I get an error message about the object not working with the property noted.
Here's the basic info in the macro:
ActiveSheet.ChartObjects("Chart 1".Activate
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = _
"=(mktblTestDREMembrProvider!R3C4,mktblTestDREMembrProvider! _
R3C7,mktblTestDREMembrProvider!R3C10)"
ActiveChart.SeriesCollection(2).Values = _
"=(mktblTestDREMembrProvider!R2C3,mktblTestDREMembrProvider! _
R2C6,mktblTestDREMembrProvider!R2C9)"
ActiveChart.SeriesCollection(3).Values = _
"=(mktblTestDREMembrProvider!R3C5,mktblTestDREMembrProvider! _
R3C8,mktblTestDREMembrProvider!R3C11)"
the R#C# is the Row and Column where the data is found. I need to cycle through each Row while keeping the Column the same.
Here is what I have further attempted:
Sub UpdateCharts()
Dim i As Integer
'********** THE FOLLOWING IS FOR THE DRE CHART, CHART 1 *********
'********** THIS IS FOR THE REPORTS TAB ************************
Dim R1a As Integer 'same row in the data, different columns
'--------------------------------All The tests use the same thing---------------------
R1a = 2 'Holds row number for first row
Do Until i = 185 '183 COMPANYIES IN THIS TIME (FEB 2002)
i = 1
Worksheets("report".Activate
With Worksheets("report"
With .ChartObjects(2) 'HbA1c
.Activate
ActiveChart.PlotArea.Select
'.PlotArea.Select
.SeriesCollection(1).Values = _
"=(mktblTestHbA1cMembrProvider!R&'R1a'&C4, mktblTestHbA1cMembrProvider!R& 'R1a'&C7, mktblTestHbA1cMembrProvider!R&'R1a'&C10)"
.SeriesCollection(2).Values = _
"=(mktblTestHbA1cMembrProvider!R&'R1a'&C3, mktblTestHbA1cMembrProvider!R& 'R1a'&C6, mktblTestHbA1cMembrProvider!R&'R1a'&C9)"
.SeriesCollection(3).Values = _
"=(mktblTestHbA1cMembrProvider!R&'R1a'&C5, mktblTestHbA1cMembrProvider!R& 'R1a'&C8, mktblTestHbA1cMembrProvider!R&'R1a'&C11)"
End With
With .ChartObjects(3) 'Lipids
.Activate
ActiveChart.PlotArea.Select
' .PlotArea.Select
.SeriesCollection(1).Values = _
"=(mktblTestLipidsMembrProvider!R&'R1a'&C4, mktblTestLipidsMembrProvider!R& 'R1a'&C7, mktblTestLipidsMembrProvider!R&'R1a'&C10)"
.SeriesCollection(2).Values = _
"=(mktblTestLipidsMembrProvider!R&'R1a'&C3, mktblTestLipidsMembrProvider!R& 'R1a'&C6, mktblTestLipidsMembrProvider!R&'R1a'&C9)"
.SeriesCollection(3).Values = _
"=(mktblTestLipidsMembrProvider!R&'R1a'&C5, mktblTestLipidsMembrProvider!R& 'R1a'&C8, mktblTestLipidsMembrProvider!R&'R1a'&C11)"
End With
With .ChartObjects(4) 'Micro
.Activate
ActiveChart.PlotArea.Select
' .PlotArea.Select
.SeriesCollection(1).Values = _
"=(mktblTestMicroMembrProvider!R&'R1a'&C4, mktblTestMicroMembrProvider!R& 'R1a'&C7, mktblTestMicroMembrProvider!R&'R1a'&C10)"
.SeriesCollection(2).Values = _
"=(mktblTestMicroMembrProvider!R&'R1a'&C3, mktblTestMicroMembrProvider!R& 'R1a'&C6, mktblTestMicroMembrProvider!R&'R1a'&C9)"
.SeriesCollection(3).Values = _
"=(mktblTestMicroMembrProvider!R&'R1a'&C5, mktblTestMicroMembrProvider!R& 'R1a'&C8, mktblTestMicroMembrProvider!R&'R1a'&C11)"
End With
End With
R1a = R1a + 1
i = i + 1
Loop
End Sub
I am open to suggestions, and definitely corrections on my WITH statement.
I recorded a Macro to begin to see how the process would work, but when I try to replicate the code from the Macro I get an error message about the object not working with the property noted.
Here's the basic info in the macro:
ActiveSheet.ChartObjects("Chart 1".Activate
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Values = _
"=(mktblTestDREMembrProvider!R3C4,mktblTestDREMembrProvider! _
R3C7,mktblTestDREMembrProvider!R3C10)"
ActiveChart.SeriesCollection(2).Values = _
"=(mktblTestDREMembrProvider!R2C3,mktblTestDREMembrProvider! _
R2C6,mktblTestDREMembrProvider!R2C9)"
ActiveChart.SeriesCollection(3).Values = _
"=(mktblTestDREMembrProvider!R3C5,mktblTestDREMembrProvider! _
R3C8,mktblTestDREMembrProvider!R3C11)"
the R#C# is the Row and Column where the data is found. I need to cycle through each Row while keeping the Column the same.
Here is what I have further attempted:
Sub UpdateCharts()
Dim i As Integer
'********** THE FOLLOWING IS FOR THE DRE CHART, CHART 1 *********
'********** THIS IS FOR THE REPORTS TAB ************************
Dim R1a As Integer 'same row in the data, different columns
'--------------------------------All The tests use the same thing---------------------
R1a = 2 'Holds row number for first row
Do Until i = 185 '183 COMPANYIES IN THIS TIME (FEB 2002)
i = 1
Worksheets("report".Activate
With Worksheets("report"
With .ChartObjects(2) 'HbA1c
.Activate
ActiveChart.PlotArea.Select
'.PlotArea.Select
.SeriesCollection(1).Values = _
"=(mktblTestHbA1cMembrProvider!R&'R1a'&C4, mktblTestHbA1cMembrProvider!R& 'R1a'&C7, mktblTestHbA1cMembrProvider!R&'R1a'&C10)"
.SeriesCollection(2).Values = _
"=(mktblTestHbA1cMembrProvider!R&'R1a'&C3, mktblTestHbA1cMembrProvider!R& 'R1a'&C6, mktblTestHbA1cMembrProvider!R&'R1a'&C9)"
.SeriesCollection(3).Values = _
"=(mktblTestHbA1cMembrProvider!R&'R1a'&C5, mktblTestHbA1cMembrProvider!R& 'R1a'&C8, mktblTestHbA1cMembrProvider!R&'R1a'&C11)"
End With
With .ChartObjects(3) 'Lipids
.Activate
ActiveChart.PlotArea.Select
' .PlotArea.Select
.SeriesCollection(1).Values = _
"=(mktblTestLipidsMembrProvider!R&'R1a'&C4, mktblTestLipidsMembrProvider!R& 'R1a'&C7, mktblTestLipidsMembrProvider!R&'R1a'&C10)"
.SeriesCollection(2).Values = _
"=(mktblTestLipidsMembrProvider!R&'R1a'&C3, mktblTestLipidsMembrProvider!R& 'R1a'&C6, mktblTestLipidsMembrProvider!R&'R1a'&C9)"
.SeriesCollection(3).Values = _
"=(mktblTestLipidsMembrProvider!R&'R1a'&C5, mktblTestLipidsMembrProvider!R& 'R1a'&C8, mktblTestLipidsMembrProvider!R&'R1a'&C11)"
End With
With .ChartObjects(4) 'Micro
.Activate
ActiveChart.PlotArea.Select
' .PlotArea.Select
.SeriesCollection(1).Values = _
"=(mktblTestMicroMembrProvider!R&'R1a'&C4, mktblTestMicroMembrProvider!R& 'R1a'&C7, mktblTestMicroMembrProvider!R&'R1a'&C10)"
.SeriesCollection(2).Values = _
"=(mktblTestMicroMembrProvider!R&'R1a'&C3, mktblTestMicroMembrProvider!R& 'R1a'&C6, mktblTestMicroMembrProvider!R&'R1a'&C9)"
.SeriesCollection(3).Values = _
"=(mktblTestMicroMembrProvider!R&'R1a'&C5, mktblTestMicroMembrProvider!R& 'R1a'&C8, mktblTestMicroMembrProvider!R&'R1a'&C11)"
End With
End With
R1a = R1a + 1
i = i + 1
Loop
End Sub
I am open to suggestions, and definitely corrections on my WITH statement.