hello,
I am working on my research and I have to generate more than 91 charts for each sheet and I would like to use macro to do that. I am still new with macros but I tried to write this one, but it is not working. I would greatly appreciate your help on this issue!
The set of data that I have looks like this
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A1[/TD]
[TD]B1[/TD]
[TD]C1[/TD]
[TD]D1[/TD]
[TD]E1[/TD]
[TD]F1[/TD]
[TD]G1[/TD]
[TD]H1[/TD]
[TD]I1[/TD]
[/TR]
[TR]
[TD]Period[/TD]
[TD]Ratio[/TD]
[TD][/TD]
[TD]Period[/TD]
[TD]Ratio[/TD]
[TD][/TD]
[TD]Period[/TD]
[TD]ratio[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2000Q1[/TD]
[TD]1.23[/TD]
[TD][/TD]
[TD]2000Q1[/TD]
[TD]0.78[/TD]
[TD][/TD]
[TD]2000Q1[/TD]
[TD]1.07[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2000Q2[/TD]
[TD]1.43[/TD]
[TD][/TD]
[TD]2000Q2[/TD]
[TD]1.12[/TD]
[TD][/TD]
[TD]2000Q2[/TD]
[TD]0.76[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2000Q3[/TD]
[TD]1.8[/TD]
[TD][/TD]
[TD]2000Q3[/TD]
[TD]1.09[/TD]
[TD][/TD]
[TD]2000Q3[/TD]
[TD]1.21[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Please note that the are other rows (I have an update button that I every time I click a new row with (period- ratio) will be added for all the columns)- also the first row with values starts at row 3
I want to create a chart for each set of data (here 3 charts)
The macro I wrote is a follows:
Sub loopChart()
Dim mychart As Chart
Dim c As Integer
Sheets("analysis").Select
c = 1
While c <> 0 #I put this condition so that the code will know that I have no more data set
Set mychart = Charts.Add
mychart.SetSourceData Source:=Range(cells(3, c)).CurrentRegion, PlotBy:=xlColumns
c = c + 3
Wend
For Each mychart In Sheets("class").ChartObjects
mychart.ChartType = xlLineMarkers
Next mychart
End Sub
I am not too sure of what I am doing is correct, but I am facing a trouble with the range. Also I know that this macro will create a new chart-sheet. how can I create all the charts on the "analysis" sheet next to the values?
I would greatly appreciate anyone's help!!
Thank you for your time
I am working on my research and I have to generate more than 91 charts for each sheet and I would like to use macro to do that. I am still new with macros but I tried to write this one, but it is not working. I would greatly appreciate your help on this issue!
The set of data that I have looks like this
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]A1[/TD]
[TD]B1[/TD]
[TD]C1[/TD]
[TD]D1[/TD]
[TD]E1[/TD]
[TD]F1[/TD]
[TD]G1[/TD]
[TD]H1[/TD]
[TD]I1[/TD]
[/TR]
[TR]
[TD]Period[/TD]
[TD]Ratio[/TD]
[TD][/TD]
[TD]Period[/TD]
[TD]Ratio[/TD]
[TD][/TD]
[TD]Period[/TD]
[TD]ratio[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2000Q1[/TD]
[TD]1.23[/TD]
[TD][/TD]
[TD]2000Q1[/TD]
[TD]0.78[/TD]
[TD][/TD]
[TD]2000Q1[/TD]
[TD]1.07[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2000Q2[/TD]
[TD]1.43[/TD]
[TD][/TD]
[TD]2000Q2[/TD]
[TD]1.12[/TD]
[TD][/TD]
[TD]2000Q2[/TD]
[TD]0.76[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2000Q3[/TD]
[TD]1.8[/TD]
[TD][/TD]
[TD]2000Q3[/TD]
[TD]1.09[/TD]
[TD][/TD]
[TD]2000Q3[/TD]
[TD]1.21[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Please note that the are other rows (I have an update button that I every time I click a new row with (period- ratio) will be added for all the columns)- also the first row with values starts at row 3
I want to create a chart for each set of data (here 3 charts)
The macro I wrote is a follows:
Sub loopChart()
Dim mychart As Chart
Dim c As Integer
Sheets("analysis").Select
c = 1
While c <> 0 #I put this condition so that the code will know that I have no more data set
Set mychart = Charts.Add
mychart.SetSourceData Source:=Range(cells(3, c)).CurrentRegion, PlotBy:=xlColumns
c = c + 3
Wend
For Each mychart In Sheets("class").ChartObjects
mychart.ChartType = xlLineMarkers
Next mychart
End Sub
I am not too sure of what I am doing is correct, but I am facing a trouble with the range. Also I know that this macro will create a new chart-sheet. how can I create all the charts on the "analysis" sheet next to the values?
I would greatly appreciate anyone's help!!
Thank you for your time