Pb macro Selection.Find

Résolu
Gilles -  
 Gilles -
Bonjour,

J'ai une erreur 91 au deuxième passage dans ma boucle For...Next
Lors de la commande Selection.Find

Si vous avez des idées je suis preneur !!

Voici mon code:

Sub Macro2()

Dim customer As Integer
Dim top As Integer
Dim client As String

Sheets("Cas RTE").Select
customer = 3
Range("AF" & customer).Select

Do While Not (IsEmpty(ActiveCell))

Sheets("top63").Select
top = 2
Range("A" & top).Select
Selection.Copy

For top = 2 To 64

Sheets("top63").Select
Range("A" & top).Select
client = Range("A" & top).Value
Selection.Copy

Sheets("Cas RTE").Select
Range("AF" & customer).Select

On Error GoTo NonTrouve
Selection.Find(What:=client, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Sheets("Cas RTE").Range("B" & customer).Value = "O"
Exit For

NonTrouve:
Sheets("Cas RTE").Range("B" & customer).Value = "N"

Next

customer = customer + 1
Sheets("Cas RTE").Select
Range("AF" & customer).Select
Loop

End Sub

MERCI de votre aide !

1 réponse

  1. gbinforme Messages postés 14930 Date d'inscription   Statut Contributeur Dernière intervention   4 744
     
    bonjour

    Je ne suis pas sûr d'avoir tout compris sans ton classeur mais il me semble que tu as des copy qui ne servent à rien alors je te propose de voir si ceci fonctionnerait :

    Sub Macro2_bis() 
    Dim customer As Integer 
    Dim top As Integer 
    Dim client As Range 
    
    customer = 3 
    With Sheets("Cas RTE") 
        Do While Not IsEmpty(.Range("AF" & customer)) 
            For top = 2 To 64 
                Set client = .Cells.Find(What:=Sheets("top63").Range("A" & top).Value, _
                    LookAt:=xlwhole)
    
                If client Is Nothing Then 
                    .Range("B" & customer).Value = "N" 
                Else 
                    .Range("B" & customer).Value = "O" 
                End If 
            Next top 
            customer = customer + 1 
        Loop 
    End With 
    End Sub 
    


    Toujours zen
    1
    1. Gilles
       
      Merci de ton aide,
      Ta proposition fonctionnait presque, sauf que si j'avais un client Top63 ("top63").Range("A" & top) dans la colonne Range("AF") sur la feuille "Cas RTE"
      Le programme indiqué "O" sur tous les clients.

      Par contre en remplaçant la fonction .Cells.Find par Selection.Find
      Je sais pas pourquoi mais ça marche nikel !
      0