Connecting lines

G

Guest

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
 
J

JE McGimpsey

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
 

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