ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Connecting lines (https://www.excelbanter.com/excel-programming/381600-connecting-lines.html)

choice[_2_]

Connecting lines
 
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

JE McGimpsey

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



All times are GMT +1. The time now is 09:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com