' // Oh, oh. Spa bon, ça. Faut pas confondre BASIC et PASCAL.
' // Là, tu déclares i comme Variant, et j comme Integer
Dim i, j As Integer
' // Même problème
Dim DesignProjet, DesignProjetGroupe, NomIng, Nom, Nom2, OccupT, OccupB As Range
' // Où as-tu déclaré ces variables ?
' // Sois pas chiche, sois précis. Utilise Worksheets plutôt que Sheet
Set total = Sheets("TabReference" )
Set brouillon = Sheets("Brouillon" )
Set Listes = Sheets("Listes" )
For i = 5 To 30
' // Gros calcul !
' // Utilise Cells(i+1, 1)
Set DesignProjetGroupe = total.Range("A" & i + 1)
' // Not XXX = 0 === XXX <> 0
' // Ce n'est pas une erreur, on est d'accord ;)
If Not DesignProjetGroupe.Value = 0 Then
' on cherche un nom de projet dans une première liste
Set Nom = Listes.Range("L8:L50" ).Find(DesignProjetGroupe.Value, LookIn:=xlValues, Lookat:=xlPart)
'mais il peut y avoir plusieurs fois ce projet dans la liste donc j'utilise un findnext avec boucle
If Not Nom Is Nothing Then
firstAddress = Nom.Address
Do
'on a trouvé un nom de projet dans la liste,
' on selectionne la cellule associée (dans la colonne d'avant)
Set DesignProjet = Nom.Offset(0, -1)
'puis on cherche le contenu de cette cellule dans une autre liste d'une autre feuille
' De même, il peut y avoir plusieurs résultat donc 2eme boucle avec findnext
Set Nom2 = brouillon.Range("A6:A300" ).Find(DesignProjet.Value, LookIn:=xlValues, Lookat:=xlPart)
If Not Nom2 Is Nothing Then
firstAddress2 = Nom2.Address
Do
'**DIVERS ACTIONS**
Set Nom2 = brouillon.Range("A6:A300" ).FindNext(Nom2)
Loop While Not Nom2 Is Nothing And Nom2.Address <> firstAddress2
End If
Set Nom = Listes.Range("L8:L50" ).FindNext(Nom)
Loop While Not Nom Is Nothing And Nom.Address <> firstAddress
End If
End If
Next
Bon, y'a quelques commentaires désagréables, mais c'est pratiquement rien.
Ajoute l'
Option Explicit, ça te permettra de ne pas oublier de déclarer tes variables
Y'a un moteur de recherche dans Excel. Mais il n'y en a qu'un
Regarde comment je ferais :
Dim ws_listes As Worksheet
Dim ws_brouill As Worksheet
Dim cel_listes As Range
Dim cel_brouill As Range
Set ws_listes = Worksheets("Listes")
Set ws_brouill = Worksheets("Brouillon")
For Each cel_listes In ws_listes.Range("L8:L50" ).Cells
For Each cel_brouill In ws_brouill.Range("A6:A300" ).Cells
If cel_listes.Value = cel_brouill.Value Then
' //ACTION
End If
Next
Next