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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| Sub Import_RoutesNames_Times()
Dim sht As Worksheet
Dim LastColumn As Long
Dim LastRow As Long
Dim RouteCol As Long
Dim K As Integer ' prochaine ligne vide dans la colonne B
Set sht = Sheets("Paddle_Data")
LastColumn = sht.Cells(1, sht.Columns.Count).End(xlToLeft).Column
LastRow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
K = 13
RouteCol = 3
For i = 1 To 10 ' lastcolumn
If Cells(12, RouteCol).Value <> sht.Cells(1, i).Value Then
'do nothing
Else
'make sure that route is not already import in the B column
If RouteCol <= 5 Then
If Cells(12, RouteCol).Value <> Cells(12, RouteCol - 1).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 2).Value Then
For j = 2 To 30 ' LastRow
If sht.Cells(j, i).Value <> "" Then
Cells(K, 2).Value = sht.Cells(j, i).Value
K = K + 1
Else
Exit For
End If
Next
i = 1
j = 2
K = Cells(Rows.Count, "B").End(xlUp).Row + 1 ' add the +1 if you like to see redundancy of the main station
RouteCol = RouteCol + 1
ElseIf Cells(12, RouteCol + 1) <> "" Then
i = 1
RouteCol = RouteCol + 1
End If
ElseIf RouteCol > 5 And RouteCol <= 8 Then
If Cells(12, RouteCol).Value <> Cells(12, RouteCol - 1).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 2).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 3).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 4).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 5).Value Then
For j = 2 To 30 ' LastRow
If sht.Cells(j, i).Value <> "" Then
Cells(K, 2).Value = sht.Cells(j, i).Value
K = K + 1
Else
Exit For
End If
Next
i = 1
j = 2
K = Cells(Rows.Count, "B").End(xlUp).Row + 1 ' add the +1 if you like to see redundancy of the main station
RouteCol = RouteCol + 1
ElseIf Cells(12, RouteCol + 1) <> "" Then
i = 1
RouteCol = RouteCol + 1
End If
ElseIf RouteCol > 8 And RouteCol <= 11 Then
If Cells(12, RouteCol).Value <> Cells(12, RouteCol - 1).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 2).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 3).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 4).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 5).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 6).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 7).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 8).Value Then
For j = 2 To 30 ' LastRow
If sht.Cells(j, i).Value <> "" Then
Cells(K, 2).Value = sht.Cells(j, i).Value
K = K + 1
Else
Exit For
End If
Next
i = 1
j = 2
K = Cells(Rows.Count, "B").End(xlUp).Row + 1 ' add the +1 if you like to see redundancy of the main station
RouteCol = RouteCol + 1
ElseIf Cells(12, RouteCol + 1) <> "" Then
i = 1
RouteCol = RouteCol + 1
End If
ElseIf RouteCol > 11 And RouteCol <= 14 Then
If Cells(12, RouteCol).Value <> Cells(12, RouteCol - 1).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 2).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 3).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 4).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 5).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 6).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 7).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 8).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 9).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 10).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 11).Value Then
For j = 2 To 30 ' LastRow
If sht.Cells(j, i).Value <> "" Then
Cells(K, 2).Value = sht.Cells(j, i).Value
K = K + 1
Else
Exit For
End If
Next
i = 1
j = 2
K = Cells(Rows.Count, "B").End(xlUp).Row + 1 ' add the +1 if you like to see redundancy of the main station
RouteCol = RouteCol + 1
ElseIf Cells(12, RouteCol + 1) <> "" Then
i = 1
RouteCol = RouteCol + 1
End If
ElseIf RouteCol > 14 And RouteCol <= 17 Then ' 17 jusqua la colonne Q
If Cells(12, RouteCol).Value <> Cells(12, RouteCol - 1).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 2).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 3).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 4).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 5).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 6).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 7).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 8).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 9).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 10).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 11).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 12).Value _
And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 13).Value And Cells(12, RouteCol).Value <> Cells(12, RouteCol - 14).Value Then
For j = 2 To 30 ' LastRow
If sht.Cells(j, i).Value <> "" Then
Cells(K, 2).Value = sht.Cells(j, i).Value
K = K + 1
Else
Exit For
End If
Next
i = 1
j = 2
K = Cells(Rows.Count, "B").End(xlUp).Row + 1 ' add the +1 if you like to see redundancy of the main station
RouteCol = RouteCol + 1
ElseIf Cells(12, RouteCol + 1) <> "" Then
i = 1
RouteCol = RouteCol + 1
End If
End If ' for routecol
End If
Next
End Sub |
Partager