Hi. I'm trying to add to a macro to create a graph with a changing range. Most of this is from a recorded macro, so please bear with the inefficiencies and many .selects!
So I'm trying to get columns A and B graphed, and they'll have a changing number of rows. I'm trying to get the range for the graph to be a rowcount.
Thanks!
Code:
Sheets("Graph Data").Select
Dim lr3 As Long
lr3 = Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & 1 & ":B" & lr3).Select
'recorded graph
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlBarClustered
ActiveChart.SetSourceData Source:=Range("'Chart Data'!$A$1:$B" & lr3)
'the above line is what the debugger doesnt approve of
ActiveChart.ApplyLayout (2)
ActiveChart.Legend.Select
Selection.Delete
ActiveSheet.ChartObjects("Chart 4").Activate
'should i rename the graph first so it'll always select the correct graph in case it isn't called chart 4 anymore?
ActiveChart.ChartTitle.Select
Selection.Format.TextFrame2.TextRange.Font.Size = 10
ActiveChart.ChartTitle.Text = "Referrals by Branch"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Referrals by Branch"
With Selection.Format.TextFrame2.TextRange.Characters(1, 19).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 19).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.Axes(xlCategory).Select
Selection.Format.TextFrame2.TextRange.Font.Size = 8
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).ReversePlotOrder = True
ActiveChart.ChartArea.Select
ActiveChart.Location Where:=xlLocationAsObject, Name:="Analysis"
So I'm trying to get columns A and B graphed, and they'll have a changing number of rows. I'm trying to get the range for the graph to be a rowcount.
Thanks!