I have the below code that creates a chart on each one of my sheets. I would like each chart to also not change size when the columns resize.
Doing a recording I can see it is usually
When I tried that with my code below the code would not run. Any other thoughts?
Doing a recording I can see it is usually
VBA Code:
.Placement = xlMove
VBA Code:
Sub CreateAICharts()
'~~~ This code Add the Graph Chart for the code scores
Dim co As ChartObject, endh%, h%, r$, sname$, suffix
'~~~ Suffix allows the code to be manipulated more easily with changing the sheet name but keeping the Suffix the same
suffix = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
For h = LBound(suffix) To UBound(suffix)
On Error Resume Next
'~~~ name of sheet is currently set for Data
sname = "Data" & suffix(h)
endi = Sheets(sname).Range("h65536").End(xlUp).Row
'~~~ -7 is put in place to remove the bottom % bar from calculation of data for graph
r = "h3:h" & endi - 7
'~~~ This area of the code indicates the shape and location of the chart
Set co = Worksheets(sname).ChartObjects.Add(Left:=Cells(1, 1).Left, Width:=305, _
Top:=Cells(endi + 3, 1).Top, Height:=200)
On Error Resume Next
'~~~ This section of the code indicates the properties of the chart
With co.Chart
.SetSourceData Source:=Sheets(sname).Range(r), PlotBy:=xlColumns
.ChartType = xlLineMarkers
.ChartTitle = "Scores"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
.PlotArea.Fill.TwoColorGradient Style:=msoGradientVertical, Variant:=1
.PlotArea.Fill.Visible = True
.PlotArea.Fill.ForeColor.SchemeColor = 37
.PlotArea.Fill.BackColor.SchemeColor = 2
.Legend.Delete
With .ChartArea.Border
.ColorIndex = 57
.ColorIndex = 57
.Weight = 2
.LineStyle = 1
End With
With co.Chart.Axes(xlValue)
.MinimumScale = 0
.MaximumScale = 8
.MinorUnitIsAuto = True
.MajorUnit = 1
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
With co.Chart
.HasTitle = True
.ChartTitle.Characters.Text = "Data"
.ChartTitle.Font.Name = "Tahoma"
.ChartTitle.Font.Size = 10
.ChartTitle.Font.Bold = True
'This did not work to prevent chart size from changing. It would not run with the code.
'.Placement = xlMove
End With
With co.Chart
.PlotArea.Height = 170
End With
End With
Next
On Error GoTo 0
End Sub