Listbox'da Filtreleme ??

Katılım
31 Ağustos 2010
Mesajlar
387
Excel Vers. ve Dili
Excel 2007-2010 Eng
Open Office Trk
Herkese selamlar. Yaptığım formda optionbutton da "var" yada "yok" seçimime göre listbox da filtreleme konusunda yardımcı olurmusunuz. Birde tarihe göre sıralama butonu için kod verebilirmisiniz. Benzer bir örnek buldum ama kendi dosyama bir türlü uyarlayamadım. Yardımlarınız için çok çok teşekkürler....
 

Ekli dosyalar

N.Ziya Hiçdurmaz

Özel Üye
Katılım
28 Nisan 2007
Mesajlar
2,218
Excel Vers. ve Dili
Office 2013 TR / 32 Bit
yanıt

Kod:
Private Sub CommandButton1_Click()
If TextBox1 <> Empty Then
Range("a2").Select
Do While Not IsEmpty(ActiveCell)
    ActiveCell.Offset(1, 0).Select
Loop
If Range("a2").Value = "" Then
    Range("a2").Value = 1
    Range("a2").Select
Else
    ActiveCell.Value = ActiveCell.Offset(-1, 0) + 1
End If
ActiveCell.Offset(0, 1).Value = TextBox1.Text
ActiveCell.Offset(0, 2).Value = Format(TextBox2, "dd.mm.yyyy")
ActiveCell.Offset(0, 3).Value = ComboBox1.Text
ActiveCell.Offset(0, 4).Value = ComboBox2.Text
End If
End Sub
Kod:
Private Sub CommandButton2_Click()
Range("a2:e65536").Sort key1:=[c2], order1:=xlAscending
End Sub
Private Sub OptionButton1_Click()
ListBox1.Clear
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths = "20,100,100,100,200"
For sat = 2 To Cells(65536, "a").End(xlUp).Row
    If Cells(sat, "d") = "Var" Then
        ListBox1.AddItem
        ListBox1.List(s, 0) = Cells(sat, "a")
        ListBox1.List(s, 1) = Cells(sat, "b")
        ListBox1.List(s, 2) = Cells(sat, "c")
        ListBox1.List(s, 3) = Cells(sat, "d")
        s = s + 1
    End If
Next
End Sub
Kod:
Private Sub OptionButton2_Click()
ListBox1.Clear
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths = "20,100,100,100,200"
For sat = 2 To Cells(65536, "a").End(xlUp).Row
    If Cells(sat, "d") = "Yok" Then
        ListBox1.AddItem
        ListBox1.List(s, 0) = Cells(sat, "a")
        ListBox1.List(s, 1) = Cells(sat, "b")
        ListBox1.List(s, 2) = Cells(sat, "c")
        ListBox1.List(s, 3) = Cells(sat, "d")
        s = s + 1
    End If
Next
End Sub
Kod:
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Var"
.AddItem "Yok"
End With
ListBox1.Clear
ListBox1.ColumnCount = 4
ListBox1.ColumnWidths = "20,100,100,100,200"
For sat = 2 To Cells(65536, "a").End(xlUp).Row
        ListBox1.AddItem
        ListBox1.List(s, 0) = Cells(sat, "a")
        ListBox1.List(s, 1) = Cells(sat, "b")
        ListBox1.List(s, 2) = Cells(sat, "c")
        ListBox1.List(s, 3) = Cells(sat, "d")
        s = s + 1
Next
End Sub
 
Katılım
31 Ağustos 2010
Mesajlar
387
Excel Vers. ve Dili
Excel 2007-2010 Eng
Open Office Trk
Çok teşekkür ederim. Ama merak ettim başka excel dosyalarımda kodu denerken ListBox1.Clear i sarı ile çizip debug hatası diyor.

Aceba Private Sub OptionButton2_Click() kodlarının alternatifi olabilirmi.
 

N.Ziya Hiçdurmaz

Özel Üye
Katılım
28 Nisan 2007
Mesajlar
2,218
Excel Vers. ve Dili
Office 2013 TR / 32 Bit
yanıt

Hatanın sebebi UserForm_Initialize olayına kodun
Kod:
ListBox1.RowSource = "A1:F" & [a65536].End(3).Row
şeklinde yazılması idi burayada ListBox1.AddItem şeklinde uygulandığında hata almayacaksınız. Diğer dosyalarınızda oluşan hatanın sebebi sanırım bu.
 
Katılım
31 Ağustos 2010
Mesajlar
387
Excel Vers. ve Dili
Excel 2007-2010 Eng
Open Office Trk
Tekrar teşekkür ederim tamamdır halloldu. sayenizde yeni kodlar öğrendim. vakit ayırıp yardımcı olduğunuz için sağolun...
 
Üst