XL 2019 rechercher à partir de userform en plusieurs feuilles

Dadi147

XLDnaute Occasionnel
Bonjour, j'ai créé un userform pour rechercher des résultats dans un tableau dans Sheet1. Pouvez-vous m'aider pour que je puisse rechercher avec les mêmes critères dans plusieurs feuilles Excel qui incluent le même tableau mais avec une valeur différente ?
 

Pièces jointes

  • TEST-05.xlsm
    30.8 KB · Affichages: 10
Solution
Bonjour

il te suffit de boucler sur les feuilles
VB:
Private Sub ComboBox1_Change()
Sheet1.Range("i1") = ComboBox1.Text
TextBox1.Value = Sheet1.Range("I2").Value
Dim a
Dim i As Long
Me.ComboBox1.Text = StrConv(Me.ComboBox1.Text, vbProperCase)
Me.ListBox1.Clear
For Each ws In ActiveWorkbook.Sheets
    With ws
        For i = 3 To Application.WorksheetFunction.CountA(.Range("A:A"))
            a = Len(Me.ComboBox1.Text)
            If Left(.Cells(i, 4).Value, a) = Left(Me.ComboBox1.Text, a) Then
                Me.ListBox1.AddItem .Cells(i, 1).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(i, 2).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(i, 3).Value...

vgendron

XLDnaute Barbatruc
Bonjour

il te suffit de boucler sur les feuilles
VB:
Private Sub ComboBox1_Change()
Sheet1.Range("i1") = ComboBox1.Text
TextBox1.Value = Sheet1.Range("I2").Value
Dim a
Dim i As Long
Me.ComboBox1.Text = StrConv(Me.ComboBox1.Text, vbProperCase)
Me.ListBox1.Clear
For Each ws In ActiveWorkbook.Sheets
    With ws
        For i = 3 To Application.WorksheetFunction.CountA(.Range("A:A"))
            a = Len(Me.ComboBox1.Text)
            If Left(.Cells(i, 4).Value, a) = Left(Me.ComboBox1.Text, a) Then
                Me.ListBox1.AddItem .Cells(i, 1).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(i, 2).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(i, 3).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(i, 4).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 4) = .Cells(i, 5).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 5) = .Cells(i, 6).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 6) = .Cells(i, 7).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 7) = .Cells(i, 8).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 8) = .Cells(i, 9).Value
                Me.ListBox1.List(ListBox1.ListCount - 1, 9) = .Cells(i, 10).Value
            End If
        Next i
    End With
Next ws
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
311 725
Messages
2 081 944
Membres
101 849
dernier inscrit
florentMIG