Lately I have been making macro's with the macrorecorder in excel and everything works fine except for the charting. Apperently the macrorecorder in 2007 is not able to create and adjust new shapes. Unfortunately I need to have a columnchart as some kind of summary at the end of my macro, but since I am not familiar with VBA I was hoping someone here could help me.
The columchart should take its data from a small table, here all the interesting data is gathered. The adjust I want to make to this chart are: position and size(B17:I36), adding datalabels, adjusting gridlines to light grey and coloring of the individual columns. The code that I have in Microsoft Visual Basic is the following:
Range("B3:B15,D3:D15").Select
Range("D3").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range( _
"'Sheet2'!$B$3:$B$15;'Sheet2'!$D$3:$D$15")
ActiveChart.ChartType = xlColumnClustered
Range("G13:N28").Select
Selection.Cut Destination:=Range("B17:I32")
Range("B17:I32").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Name = "=""SF"""
ActiveChart.SetElement (msoElementDataLabelOutSideEnd)
ActiveChart.Axes(xlValue).HasMajorGridlines = True
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Points(13).Select
ActiveWindow.SmallScroll Down:=9
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(12).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(11).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(10).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(9).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(8).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(7).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(6).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(5).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(4).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(3).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(2).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(1).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(4).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.Select
Selection.Position = xlCorner
Hopefully someone can help me with this since I have no idea how to write this in VBA.
The columchart should take its data from a small table, here all the interesting data is gathered. The adjust I want to make to this chart are: position and size(B17:I36), adding datalabels, adjusting gridlines to light grey and coloring of the individual columns. The code that I have in Microsoft Visual Basic is the following:
Range("B3:B15,D3:D15").Select
Range("D3").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range( _
"'Sheet2'!$B$3:$B$15;'Sheet2'!$D$3:$D$15")
ActiveChart.ChartType = xlColumnClustered
Range("G13:N28").Select
Selection.Cut Destination:=Range("B17:I32")
Range("B17:I32").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Name = "=""SF"""
ActiveChart.SetElement (msoElementDataLabelOutSideEnd)
ActiveChart.Axes(xlValue).HasMajorGridlines = True
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Points(13).Select
ActiveWindow.SmallScroll Down:=9
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(12).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(11).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(10).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(9).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(8).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(7).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(6).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(5).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(4).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(3).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(2).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(1).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.LegendEntries(4).Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.Select
Selection.Position = xlCorner
Hopefully someone can help me with this since I have no idea how to write this in VBA.