Plot many sheets in scatter chart

diegomucino

New Member
Joined
Apr 12, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
What about having one thousend or one hundred of sheets is there any solution to add them more quickly instead of writting every one on this code?



Sub MakeChart()
Dim rX1 As Range, rY1 As Range, rX2 As Range, rY2 As Range, rX3 As Range, rY3 As Range
Dim rChartPos As Range
Dim chtO As ChartObject

Set rX1 = Worksheets("final1").Range("F2:F2501"): Set rY1 = Worksheets("final1").Range("G2:G2501")
Set rX2 = Worksheets("final2").Range("F2:F2501"): Set rY2 = Worksheets("final2").Range("G2:G2501")
Set rX3 = Worksheets("final3").Range("F2:F2501"): Set rY3 = Worksheets("final3").Range("G2:G2501")

Set rChartPos = Worksheets("Resultados").Range("U5:Z10") ' location and dimensions of the chart
With rChartPos
Set chtO = .Parent.ChartObjects.Add(.Left, .Top, .Width, .Height)
chtO.Name = "MyChart"
End With

With chtO.Chart

.ChartType = xlXYScatterLines

' add first series
With .SeriesCollection.NewSeries
.XValues = rX1
.Values = rY1
.Name = "S1"
End With

' add second series
With .SeriesCollection.NewSeries
.XValues = rX2
.Values = rY2
.Name = "S2"
End With

' add third series
With .SeriesCollection.NewSeries
.XValues = rX3
.Values = rY3
.Name = "S3"
End With

.SetElement (msoElementChartTitleAboveChart)
.ChartTitle.Text = "My Chart Title"

End With


End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
something like this (didn't test it)
VBA Code:
for i=1 to 100
' add first series
With .SeriesCollection.NewSeries
.XValues = "='final" & i & "'!F2:F2501"
.Values = "='final" & i & "'!g2:g2501"
.Name = "S" & i
End With
next
 
Upvote 0
I think BSALV's routine looks good (I didn't test it either).

Just so you know, you're limited to 255 series in an Excel chart. But if you approach this limit, you probably won't be able to read anything in the chart.
 
Upvote 0

Forum statistics

Threads
1,215,233
Messages
6,123,771
Members
449,122
Latest member
sampak88

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