This is my data in Excel, I am trying to create a column graph from it
Data in column A is for the column labels and data in column B is for the column heights.
I need to do this through VBA so I created the graph manually whilst recording a macro. I got this code:
Sub Macro5() Range("A1:B10").Select ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select ActiveChart.SetSourceData Source:=Range("Report!$A$1:$B$10") ActiveChart.FullSeriesCollection(1).Select ActiveChart.ChartGroups(1).Overlap = 0 ActiveChart.ChartGroups(1).GapWidth = 0 ActiveChart.ChartTitle.Select ActiveChart.ChartTitle.Text = "Frequency" Selection.Format.TextFrame2.TextRange.Characters.Text = "Frequency" With Selection.Format.TextFrame2.TextRange.Characters(1, 9).ParagraphFormat .TextDirection = msoTextDirectionLeftToRight .Alignment = msoAlignCenter End With With Selection.Format.TextFrame2.TextRange.Characters(1, 9).Font .BaselineOffset = 0 .Bold = msoFalse .NameComplexScript = "+mn-cs" .NameFarEast = "+mn-ea" .Fill.Visible = msoTrue .Fill.ForeColor.RGB = RGB(89, 89, 89) .Fill.Transparency = 0 .Fill.Solid .Size = 14 .Italic = msoFalse .Kerning = 12 .Name = "+mn-lt" .UnderlineStyle = msoNoUnderline .Spacing = 0 .Strike = msoNoStrike End With ActiveChart.ChartArea.Select End Sub
Now, when I run this macro again, it doesn't give me the same graph that I created when I recorded this macro.
So, my question is why is it doing this and how do I fix it? How would I make a graph like the one I made manually from the data I have?
Recording the macro didn't work at all for me and gives me a completely different graph as you can see.
To summarize I created a graph manually and recorded a macro but running the macro doesn't create the graph I created before.