Hi all,
I would like to add a horizontal line at a 'dynamic' (value taken at time of chart creation and then fixed) point. I would ideally prefer to not use a range, as this will mean i have a column with the same number repeated. I think a way around this is using arrays, but I have never used an array in vba before.
I create the chart from data in a range, this data is pulled from another sheet using a macro, and varys in size. I assume the size of the array would have to change to fit the first set of data.
Below is the code i use to create the chart. Test, Units and Spec are set earlier in the code, and I would like the horiztonal line to be at the value of Spec.
Thanks!
I would like to add a horizontal line at a 'dynamic' (value taken at time of chart creation and then fixed) point. I would ideally prefer to not use a range, as this will mean i have a column with the same number repeated. I think a way around this is using arrays, but I have never used an array in vba before.
I create the chart from data in a range, this data is pulled from another sheet using a macro, and varys in size. I assume the size of the array would have to change to fit the first set of data.
Below is the code i use to create the chart. Test, Units and Spec are set earlier in the code, and I would like the horiztonal line to be at the value of Spec.
Code:
Dim Test As String
Dim Units As String
Dim cht As ChartObject
Dim rng As Range
Dim Spec As Double
'......other code not related to the graph creation......
Set rng = Range(Range("E4:F4"), Range("E4:F4").End(xlDown))
Set cht = ActiveSheet.ChartObjects.Add(Left := Range("H7").Left, Width := 450, Top := Range("H7").Top, Height := 250)
cht.Chart.SetSourceData Source:=rng
cht.Chart.ChartType = xlLine
cht.Chart.HasTitle = True
cht.Chart.ChartTitle.Text = Test
cht.Chart.HasLegend = False
cht.Chart.SeriesCollection(1).MarkerStyle = xlMarkerStyleDiamond
cht.Chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
cht.Chart.Axes(xlValue, xlPrimary).AxisTitle.Text = Units
Thanks!