Public Sub AddXYscatterChart()
Dim XVal(8) As Single
Dim YVal(8) As Single
Dim minimumX As Single
Dim maximumX As Single
Dim NumCharts As Long
XVal(0) = 7.885
YVal(0) = 7.78800297
XVal(1) = 11.84
YVal(1) = 11.82672596
XVal(2) = 11.986
YVal(2) = 11.79815865
XVal(3) = 11.775
YVal(3) = 11.85401344
XVal(4) = 12.76
YVal(4) = 12.8492775
XVal(5) = 12.399
YVal(5) = 11.95190716
XVal(6) = 11.704
YVal(6) = 11.92477417
XVal(7) = 10.894
YVal(7) = 10.90637398
minimumX = 7
maximumX = 15
Application.StatusBar = "Making XY scatter chart"
ActiveSheet.ChartObjects.Add Left:=180, Top:=50, Width:=1000, Height:=400
NumCharts = ActiveSheet.ChartObjects.Count
If NumCharts > 1 Then
ActiveSheet.ChartObjects(NumCharts).Left = ActiveSheet.ChartObjects(NumCharts - 1).Left + 20
ActiveSheet.ChartObjects(NumCharts).Top = ActiveSheet.ChartObjects(NumCharts - 1).Top + 20
ActiveSheet.ChartObjects(NumCharts).Height = ActiveSheet.ChartObjects(NumCharts - 1).Height
ActiveSheet.ChartObjects(NumCharts).Width = ActiveSheet.ChartObjects(NumCharts - 1).Width
End If
NumCharts = ActiveSheet.ChartObjects.Count
ActiveSheet.ChartObjects(NumCharts).Activate
Dim Achart As ChartObject
Set Achart = ActiveSheet.ChartObjects(NumCharts)
With Achart.Chart 'Set chart properties
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
.HasLegend = True
.Legend.Position = xlLegendPositionTop
.Axes(xlCategory).MajorTickMark = xlTickMarkOutside
.Axes(xlValue).MajorTickMark = xlTickMarkOutside
minimumX = minimumX * 0.95
maximumX = maximumX * 1.05
.Axes(xlValue).MinimumScale = Format(minimumX, "#####.##")
.Axes(xlValue).MaximumScale = Format(maximumX, "#####.##")
.Axes(xlCategory).MinimumScale = Format(minimumX, "#####.##")
.Axes(xlCategory).MaximumScale = Format(maximumX, "#####.##")
.HasTitle = True
.ChartTitle.Text = "Up to you" 'Adds header for entire chart
iii = 1
.SeriesCollection(iii).Values = Array(XVal)
.SeriesCollection(iii).XValues = Array(YVal)
.SeriesCollection(iii).Name = "Records"
Selection.Fill.OneColorGradient Style:=msoGradientHorizontal, Variant:=4, Degree:=0.231372549019608
.SeriesCollection(iii).Border.LineStyle = xlNone
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Characters.Text = "What you want"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Characters.Text = "Still your choice"
End With
Set Achart = Nothing
Application.StatusBar = "Completed ---- Making XY scatter chart - Start new Task"
End Sub