Excel recherche et population des valeurs dans une table

YOYO

XLDnaute Nouveau
Bonjour les experts,

Ce que je souhaite
1 - Parcourir les lignes de la feuille de travail active
2 - Trouver l'indice de la ligne dans le feuillet "PendingMonitor" correspondant a une valeur de la colonne AA
3 - Si l'indice "trouv" existe, assigner la valeur d'une colonne fixe pour cet indice du feuillet "PendingMonitor"

Voici le code ci-dessous, je recois un type mismatch runtime error.
Merci si vous pouvez m'eclairer et m'aider a rectifier ce bout de code.

NbLignes = 500
For i = 8 To NbLignes
trouv = ""
trouv = Application.Index(Worksheets("PendingMonitor").Range("C7:C3500"), _
Application.Match(Range("AA" & i).Value, 0))
If IsEmpty(trouv) Then
Range("AE" & i).Value = Range("B" & i).Value
Else
Range("AE" & i).Value = Worksheets("PendingMonitor").Range("C" & trouv).Value
End If
Next i
 

tototiti2008

XLDnaute Barbatruc
Re : Excel recherche et population des valeurs dans une table

Bonjour YOYO,

Application.Match renvoie une erreur s'il ne trouve rien.
En plus, il me semble qu'il manque un argument dans ton Match (la plage où il doit rechercher)
Personnellement, je fait un Application.CountIf pour savoir s'il y a une réponse, et seulement s'il y en a une je fait ma recherche...
 

YOYO

XLDnaute Nouveau
Re : Excel recherche et population des valeurs dans une table

Merci pour ton aide...
En fait en cherchant un peu j'ai trouve une solution...

NbLignes = 500
For i = 8 To NbLignes
Set x = Worksheets("PendingMonitor").Range("C7:C3500").Find(Range("AA" & i).Value, , xlValues, xlWhole, , , False)
If Not x Is Nothing Then
Range("AE" & i).Value = Worksheets("PendingMonitor").Range("E" & x.Row).Value
Else
Range("AE" & i).Value = Range("B" & i).Value
End If
Next i

Cependant la macro tourne tres lentement (plusieurs minutes pour afficher le resultat).
Une petite idée d'amélioration?
 

tototiti2008

XLDnaute Barbatruc
Re : Excel recherche et population des valeurs dans une table

Re,

Oui, le Countif... Find est souvent assez lent.

Pour le Match, déjà , tu dois avoir une plage où rechercher (fonction EQUIV)

Code:
Application.Match(Range("AA" & i).Value, [COLOR=red]Range("ZZ1:ZZ3500")[/COLOR], 0)
 

tototiti2008

XLDnaute Barbatruc
Re : Excel recherche et population des valeurs dans une table

Re,

ça devrait donner un truc comme ça :

Code:
NbLignes = 500
For i = 8 To NbLignes
trouv = ""
if Application.countif(Worksheets("PendingMonitor").Range("C7:C3500"),Range("AA" & i).Value) >0 then
trouv = Application.Index(Worksheets("PendingMonitor").Range("C7:C3500"), _
Application.Match(Range("AA" & i).Value,Worksheets("PendingMonitor").Range("C7:C3500"), 0))
end if
If trouv = "" Then
Range("AE" & i).Value = Range("B" & i).Value
Else
Range("AE" & i).Value = Worksheets("PendingMonitor").Range("C" & trouv).Value
End If
Next i
 

YOYO

XLDnaute Nouveau
Re : Excel recherche et population des valeurs dans une table

Merci ca marche presque super, c'est juste que j'aurai besoin de la ligne trouvée la place de la valuer de trouv (trouv.Row ne marche pas).

Range("AE" & i).Value = Worksheets("PendingMonitor").Range("C" & trouv.Row).Value
 
Dernière édition:

YOYO

XLDnaute Nouveau
Re : Excel recherche et population des valeurs dans une table

Genial, Merci! Encore une etape de franchie, ca marche...

Seulement, j'obtiens a present une Out of Memory Runtime Error...
Que faut-il adapter au code suivant pour résoudre le problème?

NbLignes = 501
For i = 8 To NbLignes
trouv = ""
indice = ""
If IsNumeric(Range("AA" & i).Value) Then
If Range("AA" & i).Value > 0 Then
Range("AA" & i).Hyperlinks.Add Anchor:=Range("AA" & i), Address=Range("AA" & i).Value
End If
End If
If Application.CountIf(Worksheets("PendingMonitor").Range("C7:C3500"), Range("AA" & i).Value) > 0 Then
indice = Application.Match(Range("AA" & i).Value, Worksheets("PendingMonitor").Range("C7:C3500"), 0)
trouv = Application.Index(Worksheets("PendingMonitor").Range("C7:C3500"), indice)
End If
If trouv = "" Or indice = "" Then
Range("AE" & i).Value = Range("B" & i).Value
Range("AF" & i).Value = Range("C" & i).Value
Range("AG" & i).Value = Range("F" & i).Value
Range("AH" & i).Value = Range("H" & i).Value
Range("AI" & i).Value = Range("G" & i).Value
Range("AJ" & i).Value = Range("I" & i).Value
Range("AK" & i).Value = Range("J" & i).Value
Range("AL" & i).Value = Range("L" & i).Value
Range("AM" & i).Value = Range("M" & i).Value
Range("AN" & i).Value = Range("N" & i).Value
Range("AO" & i).Value = Range("O" & i).Value
Range("AP" & i).Value = Range("P" & i).Value
Range("AQ" & i).Value = Range("R" & i).Value
Else
Range("AE" & i).Value = Worksheets("PendingMonitor").Range("E" & indice).Value
Range("AF" & i).Value = Worksheets("PendingMonitor").Range("F" & indice).Value
Range("AG" & i).Value = Worksheets("PendingMonitor").Range("G" & indice).Value
Range("AH" & i).Value = Worksheets("PendingMonitor").Range("M" & indice).Value
Range("AI" & i).Value = Worksheets("PendingMonitor").Range("H" & indice).Value
Range("AJ" & i).Value = Worksheets("PendingMonitor").Range("J" & indice).Value
Range("AK" & i).Value = Worksheets("PendingMonitor").Range("I" & indice).Value
Range("AL" & i).Value = Worksheets("PendingMonitor").Range("AP" & indice).Value
Range("AM" & i).Value = Worksheets("PendingMonitor").Range("U" & indice).Value
Range("AN" & i).Value = Worksheets("PendingMonitor").Range("AN" & indice).Value
Range("AO" & i).Value = Worksheets("PendingMonitor").Range("D" & indice).Value
Range("AP" & i).Value = Worksheets("PendingMonitor").Range("K" & indice).Value
Range("AQ" & i).Value = Worksheets("PendingMonitor").Range("N" & indice).Value
End If
Next i
End Sub
 

Statistiques des forums

Discussions
312 305
Messages
2 087 081
Membres
103 457
dernier inscrit
fab2614