Rechercher

J

Jon

Guest
Hello,

J'ai un petit problème avec ma macro!

J'ai une base de données avec la colonne A (no d'articles) et la colonne B (nom d'articles)

Exemple :
1 balle
2 balle 2
3 balle 3

Voici ma macro:

Option Explicit
Sub RechercheCible()
Dim Plage As Range
Dim Adresse As String
Dim C As Object
Dim Mot As String
Dim TheRow As Integer

Mot = InputBox("Numéro à chercher ?")
'Contrôles avant recherche
If Mot = "" Then Exit Sub
If Application.CountIf(Range("A:B"), Mot) = 0 Then MsgBox "Ce mot est inexistant !": Exit Sub
'Recherche du N°
Set Plage = Sheets("Accueil").Range("A:B")
With Plage
Set C = .Find(Mot)
If Not C Is Nothing Then
Adresse = C.Address
TheRow = C.Row
'Transport à la ligne du mot recherché
ActiveWindow.ScrollRow = TheRow
C.EntireRow.Range("A1:B1").Select
End If
End With
End Sub

J'aimerais pouvoir passé au suivant lorsque je tape par exemple que "balle"!!
Merci pour votre aide
 
C

CBernardT

Guest
Bonsoir Jon

Petites modifs sur la macro en espérant avoir bien compris ?

Sub RechercheCible()
Dim Plage As Range
Dim Adress1 As String, Adress2 As String, Mot as String
Dim C As Object
Dim TheRow As Integer

'Mot à chercher
Mot = InputBox("Mot à chercher ?", "SAISIE")
'Contrôles avant recherche
If Mot = "" Then Exit Sub
'Plage de recherche
Set Plage = Sheets("Accueil").Columns("A:B")
With Plage
'Première cible
Set C = .Find(What:=Mot)
If C Is Nothing Then MsgBox "Ce mot est inexistant !": Exit Sub
Adress1 = C.Address
TheRow = C.Row
'Transport à la ligne du mot recherché
ActiveWindow.ScrollRow = TheRow
C.EntireRow.Range("A1:B1").Select
'Suivantes
Do
If MsgBox("suivant ?", 4) = vbNo Then Exit Sub
Set C = .FindNext(C): If C.Address = Adress1 Then Exit Sub
Adress2 = C.Address
TheRow = C.Row
'Transport à la ligne du mot recherché
ActiveWindow.ScrollRow = TheRow
C.EntireRow.Range("A1:B1").Select
Loop While Not C Is Nothing
End With
End Sub

Cordialement

CBernardT
 

Statistiques des forums

Discussions
313 096
Messages
2 095 228
Membres
106 228
dernier inscrit
ntat