title: Coding a Scatter plot with smooth lines in VBA
body: <p>I am trying to code for a Scatter Plot using smooth lines with VBA.
  I am trying to take data off of a worksheet and create a scatter plot with lines and no markers in the same workbook different sheet using VBA.</p>
  
  <p>This is part snapshot of my worksheet</p>
  
  <p><a href="https://i.stack.imgur.com/fyyj0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fyyj0.png" alt="enter image description here"></a></p>
  
  <p>The values below 247 and between 263 to 455 in column A will have corresponding -1.75 in column B.</p>
  
  <p>The x values are in range <code>A1:A401</code> </p>
  
  <p>y-values are in range <code>B1:B401</code> </p>
  
  <p>Also I want to have title to my graph and X and Y axis labelled. I am having trouble figuring how to get the y-values to plot with the x-values instead of excel making two seperate lines on the chart.</p>
  
  <p>This is graph I need</p>
  
  <p><a href="https://i.stack.imgur.com/CHiIg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CHiIg.png" alt="enter image description here"></a></p>
  
  <p>This is the code I have used</p>
  
  <pre><code>Set xData = ThisWorkbook.Worksheets(2).Range("A1:A" &amp; LastRow_this)
  Set yData = ThisWorkbook.Worksheets(2).Range("B1:B" &amp; LastRow_this)
  
  Set GraphRange = Union(xData, yData)
  
  'Create a chart
    Set cht = ThisWorkbook.Worksheets(1).Shapes.AddChart2
  
  'Give chart some data
    cht.Chart.SetSourceData Source:=GraphRange
  
  'Determine the chart type
    cht.Chart.ChartType = xlXYScatterLines
  </code></pre>
  
  <p>This is what it gives me in Excel.</p>
  
  <p><a href="https://i.stack.imgur.com/Lg2vo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lg2vo.png" alt="enter image description here"></a></p>
  
  <p>How can I get the desired result ?</p>
  
  <p>Also what can I do if the range is dynamic ? </p>