Recherche

bonjour a tous.

la j'ai besion d'aide s.v.p..

avec l'aide de plusieurs codes trouver sur le net,

pour une recherche dans une base de donnée,par un usf, textbox et listbox, si dans une ligne de ma base de donnée d'une meme colonne

j'ai ( banc de scie ) et que j'ecris dans ma texbox le mot scie, j'ai rien qui apparait dans ma listbox,

par contre si j'ecris seulement (b) tout ce qui commence par (b) apparait dans ma lisbox.

question: y a t'il un moyen de faire pour ma recherche se fasse de maniere que (banc de scie) apparaisse si j'ecris (banc) ou (de) ou (scie)?

c'est tu possible?

je vais essayer de vous mettre mon code pour mieux comprendre.

merci a l'avance pour votre aide.

Option Explicit
Option Compare Text

Private Sub CommandButton1_Click()
Dim R As Integer

R = MsgBox("VOULEZ-VOUS VRAIMENT QUITTER ET FERMER LE PROGRAMME?", 36, "QUITTER")
Select Case R
    Case vbYes
        'Oui
 ActiveWorkbook.Close True
Application.DisplayAlerts = False
Application.Quit
    Case vbNo
        'Non
End Select
End Sub

Private Sub CommandButton2_Click()

UserForm4.Show
End Sub

Private Sub Label12_Click()

End Sub

Private Sub OptionButton1_Click()
Unload Me
UserForm3.Show

End Sub
Private Sub ListBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  UnHook_Mouse
End Sub

Private Sub ListBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  ' Définir les noms des objet à l'ouverture de l'USF
  ' sont utilisés dans le code du hook
  Set ObjUSF = Me: Set ObjList = ListBox1
  'Store the first TopIndex Value
  intTopIndex = ListBox1.TopIndex
  '
  Hook_Mouse
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  UnHook_Mouse
End Sub

Private Sub TextBox1_Change()
Dim Plage As Range, cell As Range
Dim RECHERCHE As String, Adresse As String
Dim Ligne As Integer, n As Integer
Dim C As Range
  intTopIndex = ListBox1.TopIndex
ListBox1.Clear
n = 0
RECHERCHE = TextBox1.Value
Range("B2").Select
Ligne = Sheets("ÉQUIPEMENTS").Range("B" & "65536").End(xlUp).Row
Set Plage = Sheets("ÉQUIPEMENTS").Range("B" & "1:" & "B" & Ligne)
With Plage
Set C = .Find(RECHERCHE, , xlValues)
If Not C Is Nothing Then
Adresse = C.Address
Do
    If UCase(RECHERCHE) = UCase(Left(C, Len(RECHERCHE))) Then
          ListBox1.AddItem C.Offset(0, 0), n
        ListBox1.List(n, 0) = C
         ListBox1.List(n, 1) = C.Offset(0, 1)
          ListBox1.List(n, 2) = C.Offset(0, 2)
           ListBox1.List(n, 3) = C.Offset(0, 3)
            ListBox1.List(n, 4) = C.Offset(0, 4)
             ListBox1.List(n, 5) = C.Offset(0, 5)

                n = n + 1
    End If
    Set C = .FindNext(C)
    Loop While Not C Is Nothing And C.Address <> Adresse
    End If
End With
End Sub

Private Sub TextBox2_Change()
Dim Plage As Range, cell As Range
Dim RECHERCHE As String, Adresse As String
Dim Ligne As Integer, n As Integer
Dim C As Range
ListBox1.Clear
n = 0
RECHERCHE = TextBox2.Value
Range("D2").Select
Ligne = Sheets("ÉQUIPEMENTS").Range("D" & "65536").End(xlUp).Row
Set Plage = Sheets("ÉQUIPEMENTS").Range("D" & "1:" & "D" & Ligne)
With Plage
Set C = .Find(RECHERCHE, , xlValues)
If Not C Is Nothing Then
Adresse = C.Address
Do
    If UCase(RECHERCHE) = UCase(Left(C, Len(RECHERCHE))) Then
          ListBox1.AddItem C.Offset(0, 0), n
        ListBox1.List(n, 0) = C.Offset(0, -3)
         ListBox1.List(n, 0) = C.Offset(0, -2)
          ListBox1.List(n, 1) = C.Offset(0, -1)
           ListBox1.List(n, 2) = C.Offset(0, 0)
            ListBox1.List(n, 3) = C.Offset(0, 1)
             ListBox1.List(n, 4) = C.Offset(0, 2)

                n = n + 1
    End If
    Set C = .FindNext(C)
    Loop While Not C Is Nothing And C.Address <> Adresse
    End If
End With

End Sub

Private Sub UserForm_Initialize()
TextBox1.SetFocus
ListBox1.ColumnCount = 5
ListBox1.ColumnWidths = "150;400;50;200;60"
End Sub

Private Sub TextBox2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox2 = ""
ListBox1.Clear
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
TextBox1 = ""
ListBox1.Clear
End Sub

Je ne peux pas tester sans le fichier excel lui-même.

Quelques pistes néanmoins :

UCase(RECHERCHE) = UCase(Left(C, Len(RECHERCHE)))

est à modifier, puisque ceci compare les premières lettres (à gauche = left) avec le mot recherché

Ce que je te propose sans avoir testé moi-même, c'est ceci

UCase(C) like UCase("*" & RECHERCHE & "*")

Bonjour Steelson!

un gros merci, cela fonctionne très bien .

vous faites du bon travail, et c'est très apprécié.

plutot.

Rechercher des sujets similaires à "recherche"