Sub VillesProches()
Const NbV = 7
Dim TDon(), TDst() As Variant, L1 As Long, L2 As Long, D As Double, LDst As Long, TIdx() As Long, _
TRés(), I As Long, Zkm As String, C As Long, TCMax() As Long, NbTCMax As Long
TDon = Feuil1.[A3:F3].Resize(Feuil1.Cells(1000, "A").End(xlUp).Row - 2).Value
ReDim TDst(1 To NumVsMax(UBound(TDon, 1)), 1 To 3)
For L2 = 2 To UBound(TDon): For L1 = 1 To L2 - 1
D = Dist(TDon(L1, 5), TDon(L1, 6), TDon(L2, 5), TDon(L2, 6))
If D <= 40 Then LDst = LDst + 1: TDst(LDst, 1) = D: TDst(LDst, 2) = L1: TDst(LDst, 3) = L2
Next L1, L2
IndexerFus1Col TIdx(), TDst(), LMax:=LDst
ReDim TRés(1 To UBound(TDon, 1), 1 To NbV), TCMax(1 To UBound(TDon, 1))
For I = 1 To UBound(TIdx)
LDst = TIdx(I): L1 = TDst(LDst, 2): L2 = TDst(LDst, 3)
Zkm = " (" & Int(TDst(LDst, 1) * 100 + 0.5) / 100 & " km)"
C = TCMax(L1) + 1: If C <= NbV Then TCMax(L1) = C: TRés(L1, C) = TDon(L2, 1) & Zkm: If C = NbV Then NbTCMax = NbTCMax + 1
C = TCMax(L2) + 1: If C <= NbV Then TCMax(L2) = C: TRés(L2, C) = TDon(L1, 1) & Zkm: If C = NbV Then NbTCMax = NbTCMax + 1
If NbTCMax >= UBound(TDst, 1) Then Exit For
Next I
Feuil1.[G3].Resize(UBound(TRés, 1), NbV).Value = TRés
End Sub