Faire une recherche
Résolu
cool185
Messages postés
25
Statut
Membre
-
pijaku Messages postés 13513 Date d'inscription Statut Modérateur Dernière intervention -
pijaku Messages postés 13513 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour, j'ai encore besoin de votre aide
svp comment faire une recherche en vba avec inputbox.Merci
svp comment faire une recherche en vba avec inputbox.Merci
2 réponses
-
Sub Chercher()
Dim Cherche As String
Cherche = InputBox("Recherche")
If Cherche <> "" Then
Recherche:
Cells.Find(What:=Cherche, After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Else
Exit Sub
End If
'pour recherche du suivant
Cherche = InputBox("Recherche prochain", , Cherche)
If Cherche <> "" Then GoTo Recherche
End Sub -
Merci à force de chercher voici ce que j'ai trouvé
Sub RECHERCHER_ALL() Sheets("BASE RAPP").Select Dim PALAIS As String Dim CellTrouvee As Range PALAIS = Application.InputBox("Que rechercher vous ?", "RECHERCHER") If PALAIS = "" Then Exit Sub Set CellTrouvee = Range("B:B").Find(PALAIS, Range("B1"), xlValues, xlWhole, xlByRows, xlNext) If CellTrouvee Is Nothing Then MsgBox "Pas trouvée" Else If Find = Range("B:B").Find(Value) Then MsgBox "Trouvé " Sheets("AFFICHAGE").Range("A4").EntireRow.ClearContents CellTrouvee.EntireRow.Select Selection.Copy Sheets("AFFICHAGE").Range("A4").PasteSpecial Application.CutCopyMode = False Sheets("AFFICHAGE").Activate End If End If End Sub
encore merci pour ta reponse-
-
-
Bonjour,
Find et Value sont des mots "protégés" VBA. S'il s'agit de variable, il convient donc, dans ton cas de :
- changer leur nom,
- les déclarer.
De plus, dans ton cas, tu as déjà cherché ta valeur :et CellTrouvee = Range("B:B").Find(PALAIS, Range("B1"), xlValues, xlWhole, xlByRows, xlNext)Donc pourquoi refaire un test...
Essaye ceci, (je n'ai fait que mettre ton second test en commentaire) :
Sub RECHERCHER_ALL() Sheets("BASE RAPP").Select Dim PALAIS As String Dim CellTrouvee As Range PALAIS = Application.InputBox("Que rechercher vous ?", "RECHERCHER") If PALAIS = "" Then Exit Sub Set CellTrouvee = Range("B:B").Find(PALAIS, Range("B1"), xlValues, xlWhole, xlByRows, xlNext) If CellTrouvee Is Nothing Then MsgBox "Pas trouvée" Else ' If Find = Range("B:B").Find(Value) Then MsgBox "Trouvé " Sheets("AFFICHAGE").Range("A4").EntireRow.ClearContents CellTrouvee.EntireRow.Select Selection.Copy Sheets("AFFICHAGE").Range("A4").PasteSpecial Application.CutCopyMode = False Sheets("AFFICHAGE").Activate ' End If End If End Sub
-