Create Charts with a Macro

DanExcel

New Member
Joined
Mar 6, 2002
Messages
29
Is it possible to create charts with a macro? I have sets of "x" and "y" data on over 100 worksheets and I'd like to quickly make an x-y scatter plot for every single worksheet.

Also, i dont know if it makes a difference, but the number of points is not the same on every worksheet.

Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It is possible to add charts using VBA. (and very difficult to mess about with if you record a macro to see what the code is.)

To embed a scatter chart on Sheet1 and use B2:C11 as the source data, you would use code like this:

<pre>
Dim Cht As Chart

Set Cht = Application.Charts.Add
With Cht
.ChartType = xlXYScatter
.SetSourceData Source:=Sheets("Sheet1").Range("B2:C11"), PlotBy:=xlColumns
.Location Where:=xlLocationAsObject, Name:="Sheet1"
End With
</pre>
 
Upvote 0
Mark,

Thanks alot. This is what I am looking for.

Do you (or does anyone) know how I can change the following two parts:

- How can I make it refer to x and y values that are in non-adjacent columns? (for the "Range" part)

- Is there a way to make it dynamically plot however many points there are (for example, some sheets have 10 points, some have 20, some have hundreds... they are all in the same columns just on different sheets).

Please let me know if this is unclear. Thank you all
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,292
Members
448,885
Latest member
LokiSonic

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