Advertisement
Guest User

Untitled

a guest
May 11th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.55 KB | None | 0 0
  1. Sub MyMacro()
  2.     Dim rng As Range
  3.     Dim plot As Chart
  4.     Set rng = Sheets(1).UsedRange
  5.     Dim x As Range
  6.     Dim y As Range
  7.     Set x = rng.Columns("A")
  8.     Set y = rng.Columns("B")
  9.     Set plot = Charts.Add
  10.     plot.ChartType = xlXYScatter
  11.     Dim s As Series
  12.     Dim i As Integer
  13.     For i = plot.SeriesCollection.Count To 1 Step -1
  14.         plot.SeriesCollection(i).Delete
  15.     Next i
  16.     Set s = plot.SeriesCollection.NewSeries
  17.     s.XValues = x
  18.     s.Values = y
  19.     Dim t As Trendlines
  20.     Set t = s.Trendlines
  21.     t.Add xlLinear
  22. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement