Bonsoir!!
Je suis à la recherche de conseil d'expert en matière de box!
Sur ma userform, j'initialise une combobox dés l'ouverture.
Etant donné la quantité de donnée qui se trouve dans la list, je souhaite pour effectuer un filtre via une textbox.
Jusque là, pas de souci! La sheet se filtre correctement avec la textbox.
Par contre je n'arrive pas à réinitialiser la combobox2 (avec saisie intuitive) pendant la procédure, de façon à ce que la list ne soit composée que des cellules filtrées. J'ai essayé avec des SpecialCells(xlCellTypeVisible) mais je n'y parviens pas....
Voila un morceau du code....
Option Compare Text ' pour saisie intuitive dans les combobox
Dim p, pbis, ligneEnreg, ligneEnregBis, choix1(), choix2(), tblBD(), Tblmtm()
Private Sub UserForm_Initialize() 'à l'ouverture de l'UserForm
'''Paramétrage de la combobox1
Dim n%
Set p = Sheets("PLANIF")
tblBD = p.Range("A2:D" & [A65000].End(xlUp).Row).Value ' Base de donnée = planif prearm
n = p.[A65000].End(xlUp).Row - 1
ReDim choix1(1 To n)
For i = 1 To n
choix1(i) = tblBD(i, 1) & " - " & tblBD(i, 2) & " / " & tblBD(i, 3) & " - " & tblBD(i, 4) 'Zone de recherche
Next i
Call Tri(choix1, LBound(choix1), UBound(choix1))
Me.ComboBox1.List = choix1
''Paramétrage de la combobox2
Dim nbis%
Set pbis = Sheets("MTMétier")
Tblmtm = pbis.Range("A2:N" & [A65000].End(xlUp).Row).Value ' Base de donnée = MTM
nbis = pbis.[A65000].End(xlUp).Row - 1
ReDim choix2(1 To nbis)
For Ibis = 1 To nbis
choix2(Ibis) = Tblmtm(Ibis, 1) & " - " & Tblmtm(Ibis, 2) & " / " & Tblmtm(Ibis, 7) & " / " & Tblmtm(Ibis, 14) 'Zone de recherche
Next Ibis
Call Tri(choix2, LBound(choix2), UBound(choix2))
Me.ComboBox2.List = choix2
End Sub
Private Sub CommandButton2_Click() '' bouton permettant de filtrer la sheet en fonction de la valeur saisie dans la textbox
Dim filtre As Variant
ComboBox2.Clear '''vidage de la combobox
Application.ScreenUpdating = False
filtre = TextBox12.Value
If filtre <> "" Then
Sheets("MTMétier").Activate
ActiveSheet.Range("B1", Range("B1").End(xlDown)).AutoFilter Field:=2, Criteria1:="*" & filtre & "*" '''filtre avec textbox.value
Else
Sheets("MTMétier").Activate
ActiveSheet.ShowAllData
End If
Application.Sheets("MTMétier").Activate
Dim nbis%
Set pbis = Sheets("MTMétier")
Tblmtm = pbis.Range("A2:N" & Rows.Count).End(xlUp).Row.SpecialCells(xlVisible).Value '''''' Et la... c'est le début des problèmes!
nbis = pbis.[A65000].End(xlUp).Row.SpecialCells(xlVisible) - 1
''''''''La méthode n'est surement pas la bonne pour ne récupérer que les cellules visibles dans ma combobox2.list
ReDim choix2(1 To nbis)
For Ibis = 1 To nbis
choix2(Ibis) = Tblmtm(Ibis, 1) & " - " & Tblmtm(Ibis, 2) & " / " & Tblmtm(Ibis, 7) & " / " & Tblmtm(Ibis, 14) 'Zone de recherche
Next Ibis
Call Tri(choix2, LBound(choix2), UBound(choix2))
Me.ComboBox2.List = choix2
End Sub
Private Sub ComboBox2_Change() 'saisie intuitive combobox
Application.Sheets("MTMétier").Activate
If Me.ComboBox2.ListIndex = -1 And IsError(Application.Match(Me.ComboBox2, choix2, 0)) Then
Me.ComboBox2.List = Filter(choix2, Me.ComboBox2.Text, True, vbTextCompare)
Me.ComboBox2.DropDown
Else
ComboBox2_click
End If
End Sub
Private Sub ComboBox2_click()
Application.Sheets("MTMétier").Activate
For Ibis = 1 To UBound(choix2)
If Tblmtm(Ibis, 1) & " - " & Tblmtm(Ibis, 2) & " / " & Tblmtm(Ibis, 7) & " / " & Tblmtm(Ibis, 14) = ComboBox2 Then
ligneEnregBis = Ibis
Me.Controls("TextBox5") = Tblmtm(ligneEnregBis, 7)
Me.Controls("TextBox6") = Tblmtm(ligneEnregBis, 1)
Me.Controls("TextBox7") = Tblmtm(ligneEnregBis, 2)
Me.Controls("TextBox8") = Tblmtm(ligneEnregBis, 13)
Me.Controls("TextBox11") = Tblmtm(ligneEnregBis, 14)
TextBox8.Value = Format(TextBox8.Value, "dd/mm/yyyy")
TextBox11.Value = Format(TextBox11.Value, "dd/mm/yyyy")
End If
Next Ibis
End Sub
Un gros merci d'avance à ceux qui prendront le temps de me conseiller!