Recherche d'un mot
Catégorie : Userform
Publié par veriland le 07-Aug-2013 12:20

D'abord il faut créer un Userform...il vous faut à la base une "Textbox" et un bouton "Valider"

 

 

puis vous inscrivez ce code dans le module de cet Userform

 
 


Option Explicit
' Vériland décembre 2003
Private Sub CommandButton2_Click()
    Unload Me
End Sub

Private Sub AfficheListe_Click()
Dim WS As Worksheet
Dim Plage As Range
Dim Cherche, Adresse As String
Dim Ligne, Arrivee As Variant
Dim C As Object
Range("Zone").Clear
Cherche = TextBox1
Ligne = 5
    If Cherche = "" Then Exit Sub
        Range("F2").Value = Cherche
    For Each WS In Worksheets
            Set Plage = Worksheets(WS.Name).Range("B3:N50")
        With Plage
                Set C = .Find(Cherche)
            If Not C Is Nothing Then
                    Adresse = C.Address
                Do
                    Arrivee = Mid(C.Address, 3)
                    Worksheets(WS.Name).Range("B" & Arrivee & ":N" & Arrivee).Copy F4.Range("B" & Ligne)
                    Ligne = F4.Range("" & "B" & "65536").End(xlUp).Row + 1
                    Set C = .FindNext(C)
                Loop While Not C Is Nothing And C.Address <> Adresse
            End If
        End With
    Next WS
    'ici on refait une boucle sur feuille "recherche"
    'pour traiter la couleur de la cellule (rouge/gras)
    Set Plage = F4.Range("B3:N50")
        With Plage
                Set C = .Find(Cherche)
            If Not C Is Nothing Then
                    Adresse = C.Address
              Do
                Arrivee = Mid(C.Address, 3)
                    With F4.Range(C.Address)
                      .Font.Bold = True
                      .Font.ColorIndex = 3
                    End With
                Set C = .FindNext(C)
              Loop While Not C Is Nothing And C.Address <> Adresse
            End If
        End With
Unload Me
End Sub