Adding variable horizontal line to existing variable line chart

mburrows

New Member
Joined
Nov 12, 2015
Messages
31
Hi everyone,

I have a summary-type worksheet which has a macro that searches through a much larger sheet and picks out the data that matches certain criteria. The macro spits out the date of the data and the values, next to each other, in cells E4:F4 downwards. This data also has a related minimum spec number.
Currently i am using the below code to plot a line graph of the data over time (note this is a segment of my macro, with Test, Units and Spec being set ealier):

Code:
Dim Test As String
Dim cht As ChartObject
Dim rng As Range
Dim Units As String
Dim Spec As Double

Set rng = Range(Range("E4:F4"), Range("E4:F4").End(xlDown))

Set cht = ActiveSheet.ChartObjects.Add(******=Range("H7").Left, *******=450, *****=Range("H7").Top, ********=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

What I would like to do is add a horizontal line with the value of Spec, which is set earlier in the code.

I don't mind having to add another series, or a drawing. As long as it is at the value of spec and is a straight line across the whole time period being plotted.

I hope this is clear enough!

Thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top