I'm a newbie in VBA. I have created a column chart in sheet 1 and want to move it to sheet 2.
I'm trying to use sheet index as reference but not a specific names.
I have come up with some codes and the part starting with activesheet.chartobjects.select
(6th last line) is where problems start ...
Please help and I really appreciate the help and kindness here.
Option Explicit
Sub createClusteredBarChart()
Dim myworksheet As Worksheet
Dim mysourcedata As Range
Dim mychart As Chart
Dim mychartdestination As Range
Set myworksheet = ThisWorkbook.Worksheets("sales figures")
With myworksheet
Set mysourcedata = .Range("a1:f6")
Set mychartdestination = .Range("A2:z10")
Set mychart = .Shapes.AddChart(XlChartType:=xlColumnClustered, _
Left:=mychartdestination.Cells(1).Left, Top:=mychartdestination.Cells(1).Top, _
Width:=mychartdestination.Width, Height:=mychartdestination.Height).Chart
With mychart
.Axes(xlValue).MaximumScale = 16000000
.Axes(xlValue).MajorUnit = 4000000
.ChartArea.Select
.ChartArea.Height = 216
.ChartArea.Width = 360
.ChartGroups(1).GapWidth = 65
End With
ActiveSheet.ChartObjects.Select
ActiveSheet.ChartObjects.Copy
Sheets("Sheet18").Range("a1").Paste
End With
mychart.SetSourceData Source:=mysourcedata
End Sub