Sub SnakeLine()
Dim Cel As Range
Dim CelHt As Single
Dim CelLeft As Single
Dim CelWid As Single
Dim CelRt As Single
Dim CelTop As Single
Dim CelBot As Single
Dim CelMidVert As Single
Dim CelMidHorz As Single
Dim CelVal As Integer
Dim LastCelVal As Integer
Dim Node1X As Single
Dim Node1Y As Single
Dim Node2X As Single
Dim Node2Y As Single
Dim Shp As ShapeRange
Dim Sht As Worksheet
Dim X As Long
Dim Rw As Long
Set Sht = ActiveSheet
For X = Sht.Shapes.Count To 1 Step -1
If Left(Sht.Shapes(X).Name, 3) = "Row" Then
Debug.Print Sht.Shapes(X).Name
Sht.Shapes(X).Delete
End If
Next X
For Each Cel In Range("I10:I27")
CelVal = Cel.Value
CelLeft = Cel.Left
CelWid = Cel.Width
CelRt = CelWid + CelLeft
CelTop = Cel.Top
CelHt = Cel.Height
CelBot = Cel.Top + CelHt
CelMidVert = CelTop + (CelHt / 2)
CelMidHorz = CelLeft + (CelWid / 2)
Rw = Cel.Row
Node1Y = CelTop
Node2Y = CelBot
If LastCelVal = 1 And CelVal = 1 Then
Node1X = CelRt
Node2X = CelRt
ElseIf LastCelVal = 0 And CelVal = 1 Then
Node1X = CelMidHorz
Node2X = CelRt
ElseIf LastCelVal = -1 And CelVal = 1 Then
Node1X = CelLeft
Node2X = CelRt
ElseIf LastCelVal = 1 And CelVal = 0 Then
Node1X = CelRt
Node2X = CelMidHorz
ElseIf LastCelVal = 0 And CelVal = 0 Then
Node1X = CelMidHorz
Node2X = CelMidHorz
ElseIf LastCelVal = -1 And CelVal = 0 Then
Node1X = CelLeft
Node2X = CelMidHorz
ElseIf LastCelVal = 1 And CelVal = -1 Then
Node1X = CelRt
Node2X = CelLeft
ElseIf LastCelVal = 0 And CelVal = -1 Then
Node1X = CelMidHorz
Node2X = CelLeft
ElseIf LastCelVal = -1 And CelVal = -1 Then
Node1X = CelLeft
Node2X = CelLeft
End If
ActiveSheet.Shapes.AddConnector(msoConnectorStraight, Node1X, Node1Y, Node2X, Node2Y).Select
Set Shp = Selection.ShapeRange
Debug.Print Shp.ID
Shp.Name = "Row" & Rw
With Shp.Line
.Visible = msoTrue
.Weight = 1.75
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
LastCelVal = CelVal
Next Cel
Range("I10").Select
End Sub