Hello,
I am new at VBA and I definetly need some help.
I am trying to create a XY graph with data from multiple sheets.
All the sheets have the same structure and different names. The number of sheets can vary from one file to another.
I recorded the macro of what I need but it is only working on this specific case (number of sheet = 3 and specific names).
I want to create a loop that can go through all the sheets of my document and create the plot.
Finally I want to move the graph to a new sheet at the end of the document.
Can anybody help me ?
Sub Macro8()
'
' Macro8 Macro
'
'
ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmoothNoMarkers).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "='Sheet1'!$B$6"
ActiveChart.FullSeriesCollection(1).XValues = "='Sheet1'!$F$31:$F$100"
ActiveChart.FullSeriesCollection(1).Values = "='Sheet1'!$G$31:$G$100"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "='Sheet2'!$B$6"
ActiveChart.FullSeriesCollection(2).XValues = "='Sheet2'!$F$31:$F$100"
ActiveChart.FullSeriesCollection(2).Values = "='Sheet2'!$G$31:$G$100"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "='Sheet3'!$B$6"
ActiveChart.FullSeriesCollection(3).XValues = "='Sheet3'!$F$31:$F$100"
ActiveChart.FullSeriesCollection(3).Values = "='Sheet3'!$G$31:$G$100"
ActiveChart.Axes(xlCategory).MaximumScale = 1
ActiveChart.SetElement (msoElementLegendRight)
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Chart"
Sheets("Chart").Select
Sheets("Chart").Move After:=Sheets(5)
End Sub
Thanks in advance
Martin
I am new at VBA and I definetly need some help.
I am trying to create a XY graph with data from multiple sheets.
All the sheets have the same structure and different names. The number of sheets can vary from one file to another.
I recorded the macro of what I need but it is only working on this specific case (number of sheet = 3 and specific names).
I want to create a loop that can go through all the sheets of my document and create the plot.
Finally I want to move the graph to a new sheet at the end of the document.
Can anybody help me ?
Sub Macro8()
'
' Macro8 Macro
'
'
ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmoothNoMarkers).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "='Sheet1'!$B$6"
ActiveChart.FullSeriesCollection(1).XValues = "='Sheet1'!$F$31:$F$100"
ActiveChart.FullSeriesCollection(1).Values = "='Sheet1'!$G$31:$G$100"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "='Sheet2'!$B$6"
ActiveChart.FullSeriesCollection(2).XValues = "='Sheet2'!$F$31:$F$100"
ActiveChart.FullSeriesCollection(2).Values = "='Sheet2'!$G$31:$G$100"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "='Sheet3'!$B$6"
ActiveChart.FullSeriesCollection(3).XValues = "='Sheet3'!$F$31:$F$100"
ActiveChart.FullSeriesCollection(3).Values = "='Sheet3'!$G$31:$G$100"
ActiveChart.Axes(xlCategory).MaximumScale = 1
ActiveChart.SetElement (msoElementLegendRight)
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="Chart"
Sheets("Chart").Select
Sheets("Chart").Move After:=Sheets(5)
End Sub
Thanks in advance
Martin