Hi, I am trying to adjust a macro that I have recorded which constructs a chart based on data in two different worksheets in the same workbook.
I have a 'comparison worksheet' with two drop-down cells that have a list of all the worksheets in the workbook. What I want the macro to do is create a chart based on the data in the two selected worksheets whose names are selected in the two drop-downs.
Any help on doing this would be much appreciated - I am unsure how to make the two cells a 'target' for 'Worksheet1' and 'Worksheet2'
My macro is currently this:
Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Comparison_sheet").Range("C3")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "='Worksheet1'!R11C2:R510C2"
ActiveChart.SeriesCollection(1).Values = "='Worksheet1'!R11C9:R510C9"
ActiveChart.SeriesCollection(1).Name = "=Comparison_sheet!R3C1"
ActiveChart.SeriesCollection(2).XValues = "='Worksheet2'!R11C2:R510C2"
ActiveChart.SeriesCollection(2).Values = "='Worksheet2'!R11C9:R510C9"
ActiveChart.SeriesCollection(2).Name = "=Comparison_sheet!R5C1"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Comparison_sheet"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Drag Development Comparison"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X dist (dimless)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Fx"
End With
ActiveSheet.Shapes("Chart 6").IncrementLeft -171.75
ActiveSheet.Shapes("Chart 6").IncrementTop -171.75
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.MinimumScaleIsAuto = True
.MaximumScale = 1
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = True
.MarkerSize = 3
.Shadow = False
End With
ActiveChart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 57
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = True
.MarkerSize = 3
.Shadow = False
End With
ActiveWindow.Visible = False
Windows("Drag Development.xls").Activate
Range("H36").Select
End Sub
thanks in advance
John