Faire une recherche

Résolu/Fermé
cool185 Messages postés 16 Date d'inscription dimanche 26 décembre 2010 Statut Membre Dernière intervention 28 octobre 2014 - 16 sept. 2014 à 22:27
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 - 22 sept. 2014 à 10:12
Bonjour, j'ai encore besoin de votre aide

svp comment faire une recherche en vba avec inputbox.Merci


2 réponses

Normad Messages postés 112 Date d'inscription dimanche 6 juin 2010 Statut Membre Dernière intervention 10 juin 2015 37
17 sept. 2014 à 08:06
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
0
cool185 Messages postés 16 Date d'inscription dimanche 26 décembre 2010 Statut Membre Dernière intervention 28 octobre 2014 1
Modifié par pijaku le 18/09/2014 à 13:47
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
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
18 sept. 2014 à 14:06
Bonjour,

Je trouve ceci très curieux :
If Find = Range("B:B").Find(Value) Then

Est ce utile au code? Cela fonctionne dans l'état?
0
cool185 Messages postés 16 Date d'inscription dimanche 26 décembre 2010 Statut Membre Dernière intervention 28 octobre 2014 1
22 sept. 2014 à 09:54
Cela fonctionne normalement .Voudrait tu me proposer quelque chose ?
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
22 sept. 2014 à 10:12
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
0