I recorded a macro that inserts a chart on the same sheet that has the data. My intention is to be able to run this same macro on subsequent sheets, however, when I try to run it on other sheets it just keeps going back to the first sheet to insert the chart. I have pasted the VBA macro code below. Can someone tell me how to correct it so that is will run on other sheets I select rather than just the one I recorded the macro on. Thank you!
VBA Code:
Sub Insertchart()
'
' Insertchart Macro
'
' Keyboard Shortcut: Ctrl+a
'
If Range("A3").Value <> "Position" Or Range("A4").Value = "" Then
Exit Sub
Else
Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("A1").Value
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).AxisGroup = 1
ActiveChart.FullSeriesCollection(2).ChartType = xlLine
ActiveChart.FullSeriesCollection(2).AxisGroup = 1
ActiveChart.FullSeriesCollection(1).Select
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.5
.Transparency = 0
.Solid
End With
ActiveChart.FullSeriesCollection(2).Select
ActiveChart.FullSeriesCollection(1).Select
ActiveChart.FullSeriesCollection(1).ApplyDataLabels
ActiveChart.FullSeriesCollection(1).DataLabels.Select
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(2).Select
ActiveChart.ChartArea.Select
ActiveChart.Legend.Select
ActiveChart.Legend.Select
Selection.Position = xlTop
End If
End Sub
Last edited by a moderator: