Filtrer une ListView avec 1 combobox et entre deux dates

Bonjour,

J'ai résolu le problème entre les deux dates, cela fonctionne, mais je voudrais sélectionnée encore un endroit.

Mon combobox comprend 4 critères de choix et doit sélectionné dans la colonne 2.

Après de nombreuses tentative et mes connaissances un peu limité, je commence seulement à programmé.

Je n'arrive pas à trouvé la solution.

J'ai fait un programme de test pour essayer de trouver la solution car mon programme d'origine est lourd.

Je le met en pièce jointe.

D'avance merci pour votre aide.

11test-date.xlsm (26.70 Ko)

Bonjour

en changeant

Private Sub TextBox1_Change()
TextBox1.MaxLength = 10
If Len(TextBox1) = 2 Or Len(TextBox1) = 5 Then TextBox1 = TextBox1 & "."
Filtre_Dates
End Sub

Private Sub TextBox2_Change()
TextBox2.MaxLength = 10
If Len(TextBox2) = 2 Or Len(TextBox2) = 5 Then TextBox2 = TextBox2 & "."
Filtre_Dates
End Sub

par

Private Sub TextBox1_Change()
TextBox1.MaxLength = 10
If Len(TextBox1) = 2 Or Len(TextBox1) = 5 Then TextBox1 = TextBox1 & "/"
Filtre_Dates
End Sub

Private Sub TextBox2_Change()
TextBox2.MaxLength = 10
If Len(TextBox2) = 2 Or Len(TextBox2) = 5 Then TextBox2 = TextBox2 & "/"
Filtre_Dates
End Sub

est ce que ca répond a votre demande

merci

Bonjour Iliyes,

Non c'est pas la sélection par les dates qui me pose problème, c'est que je veux ajouter un tri sur la colonne 2.

Je veux filtrer l'endroit (exemple "YVDN") par le combobox1, ensuite filtrer par les dates.

Les points dans les date c'est normal, c'est ce que je veux et c'est la pratique chez nous.

Private Sub Filtre_Dates()
If Len(TextBox1) = 10 Then deb = CDate(TextBox1)
If Len(TextBox2) = 10 Then fin = CDate(TextBox2)

ListView1.ListItems.Clear
For Lg = 2 To UBound(C)
Select Case True
Case deb <> "" And fin = "": Key1 = C(Lg, 10) >= deb
Case deb <> "" And fin <> "": Key1 = C(Lg, 10) >= deb
Key2 = C(Lg, 10) <= fin: Key1 = Key1 And Key2
Case deb = "" And fin = "": Key1 = True
End Select
If Key1 Then
Set List = ListView1.ListItems.Add(Text:=C(Lg, 1))
For i = 2 To UBound(C, 2)
List.ListSubItems.Add , , C(Lg, i)
'C(Lg, 9) = Format(C(Lg, 9), "0## ### ## ##")
Next i
End If
Next Lg
End Sub

Hello à tous,

Voila une façon de faire (un peu bourrin j'en conviens ) :

A toi de l'adapter à ton code

    Dim loData As ListObject
    Dim lngRow As Long
    Dim rngData As Range, rngRow As Range

    Set loData = Worksheets(1).ListObjects("Tableau1")

    loData.Range.AutoFilter Field:=2, Criteria1:=UserForm1.ComboBox1.Text
    loData.Range.AutoFilter Field:=10, Criteria1:=">=" & CLng(CDate(UserForm1.TextBox1.Value)), _
        Operator:=xlAnd, Criteria2:="<=" & CLng(CDate(UserForm1.TextBox2.Value))
    On Error Resume Next
    lngRow = loData.ListColumns(1).DataBodyRange.SpecialCells(xlCellTypeVisible).Count
    If Err.Number = 0 Then

        With ListView1
            .ListItems.Clear
            With .ColumnHeaders
                  .Clear
                 .Add Text:="CODE", Width:="50", Alignment:=fmAlignmentLeft
                 .Add Text:="NOM", Width:="120", Alignment:=fmAlignmentLeft
                 .Add Text:="Prénom", Width:="120", Alignment:=fmAlignmentLeft
                 .Add Text:="Naisance", Width:="90", Alignment:=fmAlignmentLeft
                 .Add Text:="Ville", Width:="90", Alignment:=fmAlignmentLeft
                 .Add Text:="Pays", Width:="70", Alignment:=fmAlignmentLeft
                 .Add Text:="Fonction", Width:="100", Alignment:=fmAlignmentLeft
                 .Add Text:="AFF", Width:="60", Alignment:=lvwColumnCenter
                 .Add Text:="Contact", Width:="100", Alignment:=lvwColumnCenter
                 .Add Text:="Date", Width:="90", Alignment:=lvwColumnCenter
              End With
                 .Gridlines = True
                 .BorderStyle = ccFixedSingle
                 .FullRowSelect = True
                 .View = lvwReport
                 .Width = 1100
        End With
        Set rngData = loData.DataBodyRange.SpecialCells(xlCellTypeVisible)
        For Each rngRow In rngData.Rows
               Set List = ListView1.ListItems.Add(, , rngRow.Cells(1).Text)
                For i = 2 To 10
                    List.ListSubItems.Add , , rngRow.Cells(1, i).Text
                Next i
        Next rngRow

    Else
            With ListView1
            .ListItems.Clear
            With .ColumnHeaders
                  .Clear
                 .Add Text:="CODE", Width:="50", Alignment:=fmAlignmentLeft
                 .Add Text:="NOM", Width:="120", Alignment:=fmAlignmentLeft
                 .Add Text:="Prénom", Width:="120", Alignment:=fmAlignmentLeft
                 .Add Text:="Naisance", Width:="90", Alignment:=fmAlignmentLeft
                 .Add Text:="Ville", Width:="90", Alignment:=fmAlignmentLeft
                 .Add Text:="Pays", Width:="70", Alignment:=fmAlignmentLeft
                 .Add Text:="Fonction", Width:="100", Alignment:=fmAlignmentLeft
                 .Add Text:="AFF", Width:="60", Alignment:=lvwColumnCenter
                 .Add Text:="Contact", Width:="100", Alignment:=lvwColumnCenter
                 .Add Text:="Date", Width:="90", Alignment:=lvwColumnCenter
              End With
                 .Gridlines = True
                 .BorderStyle = ccFixedSingle
                 .FullRowSelect = True
                 .View = lvwReport
                 .Width = 1100
        End With

    End If
Rechercher des sujets similaires à "filtrer listview combobox entre deux dates"