Creating several charts using a loop in vba

HMN93

New Member
Joined
May 31, 2014
Messages
20
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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top