View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Connecting lines

One way:

Public Sub DrawLines()
' cdConvToRads = Pi / 180
Const cdConvToRads As Double = 0.0174532925199433
Const cdScaleFactor As Double = 2
Dim rCell As Range
Dim dAngle As Double
Dim dLen As Double
Dim dStartX As Double
Dim dStartY As Double
Dim dEndX As Double
Dim dEndY As Double

dStartX = 100
dStartY = 100
With ActiveSheet
For Each rCell In Range(.Cells(2, 1), _
.Cells(.Rows.Count, 1).End(xlUp))
With rCell
dAngle = .Value * cdConvToRads
dLen = .Offset(0, 1).Value * cdScaleFactor
End With
dEndX = dStartX + dLen * Sin(dAngle)
dEndY = dStartY - dLen * Cos(dAngle)
.Shapes.AddLine dStartX, dStartY, dEndX, dEndY
dStartX = dEndX
dStartY = dEndY
Next rCell
End With
End Sub

In article ,
choice wrote:

If I have a range in excel that has angles in degrees in one column and
lengths in the next.
ANGLE LENGTH
90 5
225 6
90 5

How could i draw a line with segments that have those dimensions (assuming
north is up) (Those dimension should end up drawing something like a Z)

Thanks in advance