I wrote the following program that extracts pairs of points that are a given distance and given elevation difference from each other from a list of XYZ points (columns 2 3 and 4 respective). The problem is it contains a nested for loop which I believe causes too many iterations and thus for large amounts of points (>1000) the routine takes an unreasonable time to complete. What can I do to optimise this algorithm?
Regards,
Amine
Sub Test1()
Columns("H:K").Select
Selection.ClearContents
c3 = 2
For c2 = 2 To 10
For c1 = c2 + 1 To 10
If Sqr((Cells(c2, 2) - Cells(c1, 2)) ^ 2 + (Cells(c2, 3) - Cells(c1, 3)) ^ 2) = 1 Then
If Abs(Cells(c1, 4) - Cells(c2, 4)) = 10 Then
Cells(c3, 8) = Cells(c1, 2)
Cells(c3, 9) = Cells(c1, 3)
Cells(c3, 10) = Cells(c2, 2)
Cells(c3, 11) = Cells(c2, 3)
c3 = c3 + 1
End If
End If
Next c1
Next c2
End Sub