Faire une recherche

Résolu
cool185 Messages postés 16 Date d'inscription   Statut Membre Dernière intervention   -  
pijaku Messages postés 12263 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


2 réponses

Normad Messages postés 112 Date d'inscription   Statut Membre Dernière intervention   40
 
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   Statut Membre Dernière intervention   1
 
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   Statut Modérateur Dernière intervention   2 761
 
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   Statut Membre Dernière intervention   1
 
Cela fonctionne normalement .Voudrait tu me proposer quelque chose ?
0
pijaku Messages postés 12263 Date d'inscription   Statut Modérateur Dernière intervention   2 761
 
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