Sub ModifierVol()
Dim tabMod() As Variant
With Sheets("Modification")
fin = .Range("A" & .Rows.Count).End(xlUp).Row 'dernière ligne non vide de la colonne A
tabMod = .Range("A2:F" & fin).Value 'récupère tout le tableau
For i = LBound(tabMod, 1) + 1 To UBound(tabMod, 1) Step 2 'on parcourt les lignes du tableau de 2 en 2
If tabMod(i, 3) = "" Then 'si Flight_No vide
tabMod(i, 3) = "AF" & Format(i / 2, "0000") 'on place un numéro de vol bidon avec la compagnie AF
tabMod(i, 5) = Format(i / 2, "0.000")
Else
If IsNumeric(Mid(tabMod(i, 3), 3, 1)) Then 'si c'est un nom de compagnie sur 3 caractères
NomCompagnie = Left(tabMod(i, 3), 2)
Else
NomCompagnie = Left(tabMod(i, 3), 3)
End If
Numvol = CInt(WorksheetFunction.Substitute(tabMod(i, 3), NomCompagnie, "")) + 20 'on remplace le numéro de vol par Num+20
tabMod(i, 5) = Numvol
End If
Next i
.Range("A2:F" & fin) = tabMod 'on colles les résultats dans la feuille
.Range("E2:E" & fin).NumberFormat = "00000" 'on applique un format pour afficher les numéros sur 5 caractères
End With
End Sub