RechercheV

Fermé
alikan - 14 juin 2016 à 16:31
michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 - 15 juin 2016 à 09:00
Bonjour,

j'essaie de faire un rechercheV avec VBA, tant que les données se trouvent la requête s'exécute mais une fois il tombe sur une valeur introuvable dans l'autre feuille il m'affiche une erreur : voici le code

Sub Bouton3_Cliquer()

Dim i As Integer
Dim j As Integer
Dim var As String

For i = 2 To 260
For j = 2 To 47

If IsEmpty(Sheets("Feuil3").Range("A" & j)) Then j = j + 1

var = WorksheetFunction.VLookup(Sheets("Feuil1").Range("A" & i), Sheets("Feuil3").Range("A:B"), 2, False)

If IsError(var) Then
MsgBox ("valeur introuvable")


Else

Sheets("Feuil1").Range("C" & i).Value = WorksheetFunction.VLookup(Sheets("Feuil1").Range("A" & i), Sheets("Feuil3").Range("A:B"), 2, False)




End If

Next j
Next i

End Sub


Ici le IsError ne marche pas j'ai essayé avec var = "" ca ne marche pas non plus.

Merci de maider :(

2 réponses

michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 312
14 juin 2016 à 18:39
Bonjour

Sans voir le classeur, donc réponse aléatoire

On Error GoTo Vide
If IsEmpty(Sheets("Feuil3").Range("A" & j)) Then j = j + 1
Var = WorksheetFunction.VLookup(Sheets("Feuil1").Range("A" & i), Sheets("Feuil3").Range("A:B"), 2, False)
Else
Sheets("Feuil1").Range("C" & i).Value = WorksheetFunction.VLookup(Sheets("Feuil1").Range("A" & i), Sheets("Feuil3").Range("A:B"), 2, False)
End If
1:
Next j
Next i

Exit Sub
Vide:
Rep = MsgBox("valeur introuvable", vbAbortRetryIgnore)
If Rep > 3 Then GoTo 1
End Sub
--
 Michel
0
michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 312
15 juin 2016 à 09:00
0