1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| Option Compare Text
Sub Arborescence()
Dim p As String
Dim DerLig As Long
Dim Niv As String, Niv1 As String, Niv2 As String, Niv3 As String
Dim N1 As Integer, N2 As Integer, N3 As Integer
p = "."
Application.ScreenUpdating = False
Sheets("Convoyage de la canne (1-2)").Activate
DerLig = Range("D" & Rows.Count).End(xlUp).Row
Range("G5:G" & DerLig).ClearContents
Niv1 = Cells(4, "D")
Niv2 = Cells(4, "E")
Niv3 = Cells(4, "F")
N1 = 0
N2 = 0
N3 = 0
For i = 5 To DerLig
If Cells(i, "D") <> Niv1 Then
N1 = N1 + 1
Cells(i, "G") = N1
N2 = 0
N3 = 0
Niv1 = Cells(i, "D")
ElseIf Cells(i, "D") = Niv1 And Cells(i, "E") <> "" Then
If Cells(i, "E") <> Niv2 Then
If Cells(i, "F") <> "" Then
N2 = N2 + 1
N3 = N3 + 1
Cells(i, "G") = N1 & p & N2 & p & N3
Niv2 = Cells(i, "E")
Else
N2 = N2 + 1
Cells(i, "G") = N1 & p & N2
N3 = 0
Niv2 = Cells(i, "E")
End If
ElseIf Cells(i, "E") = Niv2 Then
If Cells(i, "F") <> "" Then
N3 = N3 + 1
Cells(i, "G") = N1 & p & N2 & p & N3
Niv3 = Cells(i, "F")
End If
End If
End If
Next i
End Sub |
Partager