Limite utilisation boucle SI
Bonjour tout le monde,
Qq'un sait il s'il y a une limite dans l'utilisation du nombre de test dans une bouble for ?
Lors de l'exécution de mon code, je reçois l'erreur "Next without For"...
Sub test()
A = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
B = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
Fin = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
C = 0
D = 1
With Sheets("Sheet3")
'Sheets("Sheet1").Columns("A:F").Copy Destination:=Sheets("Sheet3").Range("A1")
'Sheets("Sheet2").Range("A2:F" & B).Copy Destination:=Sheets("Sheet3").Range("A" & A + 1)
Do While C <> D
For k = 2 To Fin
If IsEmpty(Cells(k, 6)) = False Then
For i = 2 To Fin
If Left(Cells(i, 5), 6) = Cells(k, 1) Then
If Right(Cells(i, 5), 5) = Cells(k, 4) Then
If Right(Left(Cells(i, 5), 12), 3) = Cells(k, 3) Then
If Len(Cells(k, 2)) = 1 Then
If Right(Left(Cells(i, 5), 8), 1) = WorksheetFunction.Concatenate(Cells(k, 2)) Then
Cells(i, 9) = Cells(k, 1)
Cells(i, 9).Interior.Color = vbGreen
Cells(i, 10) = Cells(k, 4)
Cells(i, 11) = Cells(k, 6)
Cells(i, 6) = Cells(k, 6)
Else:
If Len(Cells(k, 2)) = 2 Then
If Right(Left(Cells(i, 5), 8), 2) = WorksheetFunction.Concatenate(Cells(k, 2)) Then
Cells(i, 9) = Cells(k, 1)
Cells(i, 9).Interior.Color = vbGreen
Cells(i, 10) = Cells(k, 4)
Cells(i, 11) = Cells(k, 6)
Cells(i, 6) = Cells(k, 6)
End If
End If
End If
End If
End If
Next i
End If
Next k
D = C
C = Application.WorksheetFunction.CountIf(Range("F2:F" & Fin), 2)
Cells(Fin + 5, 3) = C
Cells(Fin + 6, 3) = D
Loop
End With
End SubUne idée svp ?
Merci d'avance !
Il te manque un End If.
Remplace le Else: If par un ElseIf et ajoute un nouveau End If en première position et normalement ça devrait rentrer dans l'ordre.
For k = 2 To Fin
If IsEmpty(Cells(k, 6)) = False Then
For i = 2 To Fin
If Left(Cells(i, 5), 6) = Cells(k, 1) Then
If Right(Cells(i, 5), 5) = Cells(k, 4) Then
If Right(Left(Cells(i, 5), 12), 3) = Cells(k, 3) Then
If Len(Cells(k, 2)) = 1 Then
If Right(Left(Cells(i, 5), 8), 1) = WorksheetFunction.Concatenate(Cells(k, 2)) Then
Cells(i, 9) = Cells(k, 1)
Cells(i, 9).Interior.Color = vbGreen
Cells(i, 10) = Cells(k, 4)
Cells(i, 11) = Cells(k, 6)
Cells(i, 6) = Cells(k, 6)
ElseIf Len(Cells(k, 2)) = 2 Then
If Right(Left(Cells(i, 5), 8), 2) = WorksheetFunction.Concatenate(Cells(k, 2)) Then
Cells(i, 9) = Cells(k, 1)
Cells(i, 9).Interior.Color = vbGreen
Cells(i, 10) = Cells(k, 4)
Cells(i, 11) = Cells(k, 6)
Cells(i, 6) = Cells(k, 6)
End If
End If
End If
End If
End If
End If
Next i
End If
Next knon il n'y aucune limite de condition dans une boucle for , par contre ce message d'erreur veut dire qu'il y a des "if" sans "end if"
si je ne me trompe pas il manque 2 "end if "
Très bien merci c'est ok!
Par compte nouveau problème,
La finction Concatenate ne fonctionne pas et fait renvoyer l'erreur "Object doesn't support this property or method...
Est ce que qq'un connait l'utilisation de cette fonction et pourrait m'aider svp ?
la fonction concatener prend au minimum 2 paramètre de type String (logique vu qu'il va coller les 2 chaine de caractère ensemble))
or dans votre code vous avez qu'une seul variable de plus ce n'est pas une chaîne de caractère mais un cells