CheckBox ile ListBox'da Filtreleme

cocoa35

Altın Üye
Katılım
6 Eylül 2007
Mesajlar
654
Excel Vers. ve Dili
excel 2016 32 Bit ve Excel 2020 32 Bit Türkçe ve İngilizce
Altın Üyelik Bitiş Tarihi
10-12-2024
Merhaba üstatlar, Ekli örnek dosyada UserForm üstünde bulunan CheckBox'lar ile ListBox'da Filtreleme yapmak istiyorum, mesela CheckBox'da "Bilgilendirme" yazıyor ise onu tıkladığımda ListBox'da sadece "Bilgilendirme" yazan satırlar gösterilsin bu konuda yardım lütfen
 

Ekli dosyalar

veyselemre

Özel Üye
Katılım
9 Mart 2005
Mesajlar
3,642
Excel Vers. ve Dili
Pro Plus 2021
Kod:
Dim lst
Private Sub CommandButton1_Click()
    listele
End Sub
Private Sub UserForm_Initialize()
    With Sheets("Musteriler")
        lst = .Range("A2:I" & .Cells(Rows.Count, 1).End(3).Row).Value
    End With
    With ListBox1
        .ColumnCount = 9
        .ColumnWidths = "70;50;50;60;60;60;70;60;60"    ' veya  "40;80;80;40;110;120;0;0;0;70;0"
        .List = lst
    End With
End Sub
Sub listele()
    With ListBox1
        .List = lst
        If CheckBox1.Value Or CheckBox2.Value Or CheckBox3.Value Then
            For i = .ListCount - 1 To 0 Step -1
                If Not ((CheckBox1.Value And .List(i, 7) = CheckBox1.Caption) Or _
                        (CheckBox2.Value And .List(i, 7) = CheckBox2.Caption) Or _
                        (CheckBox3.Value And .List(i, 7) = CheckBox3.Caption)) Then .RemoveItem i
            Next i
        End If
        If CheckBox4.Value Or CheckBox5.Value Or CheckBox6.Value Then
            For i = .ListCount - 1 To 0 Step -1
                If Not ((CheckBox4.Value And .List(i, 8) = CheckBox4.Caption) Or _
                        (CheckBox5.Value And .List(i, 8) = CheckBox5.Caption) Or _
                        (CheckBox6.Value And .List(i, 8) = CheckBox6.Caption)) Then .RemoveItem i
            Next i
        End If
    End With
End Sub
 
Son düzenleme:

cocoa35

Altın Üye
Katılım
6 Eylül 2007
Mesajlar
654
Excel Vers. ve Dili
excel 2016 32 Bit ve Excel 2020 32 Bit Türkçe ve İngilizce
Altın Üyelik Bitiş Tarihi
10-12-2024
Çok teşekkürler Veysel Emre bey harika çalışıyor..:)
 

cocoa35

Altın Üye
Katılım
6 Eylül 2007
Mesajlar
654
Excel Vers. ve Dili
excel 2016 32 Bit ve Excel 2020 32 Bit Türkçe ve İngilizce
Altın Üyelik Bitiş Tarihi
10-12-2024
Kod:
Dim lst
Private Sub CommandButton1_Click()
    listele
End Sub
Private Sub UserForm_Initialize()
    With Sheets("Musteriler")
        lst = .Range("A2:I" & .Cells(Rows.Count, 1).End(3).Row).Value
    End With
    With ListBox1
        .ColumnCount = 9
        .ColumnWidths = "70;50;50;60;60;60;70;60;60"    ' veya  "40;80;80;40;110;120;0;0;0;70;0"
        .List = lst
    End With
End Sub
Sub listele()
    With ListBox1
        .List = lst
        If CheckBox1.Value Or CheckBox2.Value Or CheckBox3.Value Then
            For i = .ListCount - 1 To 0 Step -1
                If Not ((CheckBox1.Value And .List(i, 7) = CheckBox1.Caption) Or _
                        (CheckBox2.Value And .List(i, 7) = CheckBox2.Caption) Or _
                        (CheckBox3.Value And .List(i, 7) = CheckBox3.Caption)) Then .RemoveItem i
            Next i
        End If
        If CheckBox4.Value Or CheckBox5.Value Or CheckBox6.Value Then
            For i = .ListCount - 1 To 0 Step -1
                If Not ((CheckBox4.Value And .List(i, 8) = CheckBox4.Caption) Or _
                        (CheckBox5.Value And .List(i, 8) = CheckBox5.Caption) Or _
                        (CheckBox6.Value And .List(i, 8) = CheckBox6.Caption)) Then .RemoveItem i
            Next i
        End If
    End With
End Sub
Veysel Emre bey Yukarıdaki kodlar güzel çalışıyor ancak ben tümünü göstertmek için checkbox ekledim ve ona "Tümü" yazdım onu nasıl bu formüle uygulayabiliriz tümü dediğimde diğer checkboxlardaki işaretlerin kalkması gerekiyor
 
Üst