Excel macro to connect points as line on graph

Joined
Jun 8, 2010
Messages
2
Reaction score
0
I have a button that will take two cells and plot that point on a graph I have on the excel sheet. I want it now to connect each point that is placed on the graph in a line to the previous points. I tried to store the points each time, but when I click the button to plot a new point, it clears any previous points. I also can't set an Array as public.
*
I have attached the file, but if it doesn't work here is some of the code I use to plot the points in the first place. Maybe it's not as clean as it could be, but i'm a novice Mech. Engineer using excel.
*
*
*
Private Sub CommandButton2_Click()
*
i = i + 1
Plot_point.plot (i)
*
End Sub
*
*
*
*
Sub plot(j As Variant)
Dim ctObject As ChartObject
Dim Cht As Chart
Dim scSeries As SeriesCollection
Dim PreviousX As Variant
Dim PreviousY As Variant
*
Set ctObject = Worksheets("How to find Psat").ChartObjects(1)
Set Cht = ctObject.Chart
Set scSeries = Cht.SeriesCollection
*
'''''This is where I tried to store the previous values
If j > 1 Then
PreviousX = rgX
PreviousY = rgY
End If
*
rgX = ThisWorkbook.Sheets("How to find Psat").Range("D37")
rgY = ThisWorkbook.Sheets("How to find Psat").Range("D42")
*
*
''''''This didn't work too well . . .
If j > 1 Then
Set dropline = ActiveSheet.Shapes.AddLine(PreviousX, PreviousY, rgX, rgY)
End If
*
*
With scSeries.NewSeries
.Name = Str(ThisWorkbook.Sheets("How to find Psat").Range("D38")) + _
"° WB H=" + Str(ThisWorkbook.Sheets("How to find Psat").Range("D43"))
.Border.ColorIndex = 2
.XValues = rgX
.Values = rgY
.MarkerStyle = xlCircle
.MarkerForegroundColorIndex = 5
.MarkerSize = 6
End With
*
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top