Sauter les lignes

Bonjour

j'ai fait le code VBA qui permet de retrouver les lignes avec n° vol identique et copier les lignes concernées dans la nouvelle feuille comme le code suivant

Si on est dans cas 1, j'ai déjà copier les lignes concernées(ligne2,3,4), je voudrais passer mon curseur à ligne 5(i=5) directement sans détecter ligne 3 et 4. Item pour cas 2. Comment puis-je faire svp

Merci d'avance!

 nbL =Range("A65000").End(xlUp).Row
x = Application.Match("n° vol ", Range("A1:Z1"), 0)
   For i = 2 To nbL Step 1
'cas 1
if cells(i,x)=cells(i+1,x) and cells(i+1,x)=cells(i+2,x) then 
range(cells(i,x),cells(i+2,x)).copy   
'coller......
'cas 2
else if cells(i,x)=cells(i+1,x) and cells(i+1,x)<>cells(i+2,x) then
range(cells(i,x),cells(i+1,x)).copy
'coller...
end if  
    next i 

Bonjour

Il faut changer le type de boucle

Mais je te donne une solution sans tests faits

Si pas ça

Sub test()
  nbl = Range("A65000").End(xlUp).Row
  x = Application.Match("n° vol ", Range("A1:Z1"), 0)
  i = 2
  While i <= nbl
    'cas 1
    If Cells(i, x) = Cells(i + 1, x) And Cells(i + 1, x) = Cells(i + 2, x) Then
      Range(Cells(i, x), Cells(i + 2, x)).Copy
      'coller......
      i = i + 2
    'cas 2
    ElseIf Cells(i, x) = Cells(i + 1, x) And Cells(i + 1, x) <> Cells(i + 2, x) Then
      Range(Cells(i, x), Cells(i + 1, x)).Copy
      'coller...
      i = i + 1
    End If
    i = i + 1
  Wend
End Sub

ça a l'air marche bien, merci Banzai64

Rechercher des sujets similaires à "sauter lignes"