• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

İki tarih arasındaki verileri Listbox'a almak

Katılım
24 Aralık 2008
Mesajlar
71
Excel Vers. ve Dili
2007 türkçe
Bu konuda forumda birçok örnek buldum fakat benim istediğim biraz farklı.Comboboxtan seçtiğim tarihe ait veriler geliyor Listbox'a ama ben bir combobox daha ekleyip iki tarih arasındaki tüm verileri almak istiyorum .Örnek dosyam ektedir.Yardımlarınızı bekliyorum.
 

Ekli dosyalar

Selamlar,

İlk olarak çalışmanıza bir adet ComboBox daha ekleyin. Muhtemelen adı ComboBox3 olacak. Eğer sizde farklı olursa aşağıdaki kodda kırmızı renkli bölümü ona göre değiştirin.

GÖSTER isimli butonunuza aşağıdaki kodu uygulayın.

Kod:
Private Sub CommandButton9_Click()
On Local Error Resume Next
t1 = CStr(ComboBox2.Value)
t2 = CStr([COLOR=red]ComboBox3.Value[/COLOR])
With ListBox1
    .ColumnCount = 8
    .Clear
    .RowSource = ""
    For i = 2 To Sheets("Sayfa2").Range("a65536").End(3).Row
        tarih = CStr(Format(Sheets("Sayfa2").Cells(i, 1).Value, "dd mmmm dddd"))
            If tarih >= t1 And tarih <= t2 Then
                .AddItem Format(Sheets("Sayfa2").Cells(i, 1).Value, "dd mmmm dddd")
                .List(ListBox1.ListCount - 1, 1) = Sheets("Sayfa2").Cells(i, 2).Value
                .List(ListBox1.ListCount - 1, 2) = Sheets("Sayfa2").Cells(i, 3).Value
                .List(ListBox1.ListCount - 1, 3) = Sheets("Sayfa2").Cells(i, 4).Value
                .List(ListBox1.ListCount - 1, 4) = Sheets("Sayfa2").Cells(i, 5).Value
                .List(ListBox1.ListCount - 1, 5) = Sheets("Sayfa2").Cells(i, 6).Value
                .List(ListBox1.ListCount - 1, 6) = Sheets("Sayfa2").Cells(i, 7).Value
            End If
    Next i
End With
CommandButton11_Click 'bu butona bas
End Sub


UserForm_Initialize kodunuzuda aşağıdaki ile değiştirin.

Kod:
Private Sub UserForm_Initialize()
    Dim X1 As Long, Y1 As Long, Y2 As Long, X2 As Long
    Dim CX As Double, CY As Double
    Dim MyCtrl As Control
        
        X1 = Application.Width
        Y1 = Application.Height
        X2 = Me.Width
        Y2 = Me.Height
        CX = X1 / X2
        CY = Y1 / Y2
        Me.Width = X1
        Me.Height = Y1
        For Each MyCtrl In Me.Controls
            MyCtrl.Top = MyCtrl.Top * CY
            MyCtrl.Left = MyCtrl.Left * CX
            MyCtrl.Width = MyCtrl.Width * CX
            MyCtrl.Height = MyCtrl.Height * CY
            On Error Resume Next
                MyCtrl.Font.Size = MyCtrl.Font.Size * CY
            On Error GoTo 0
        Next
    Sheets("Sayfa2").Activate
    Label6.Caption = Range("A1")
    Label7.Caption = Range("B1")
    Label8.Caption = Range("D1")
    Label9.Caption = Range("E1")
    Label10.Caption = Range("F1")
    Label11.Caption = Range("G1")
    ListBox1.ColumnCount = 8
    ListBox1.ColumnWidths = "100;160;0;85;85;85"
    ListBox1.ListIndex = ListBox1.ListCount - 1
    
    Sheets("sayfa2").Select
    
    Set s1 = Sheets("sayfa2")
    
    For x = 2 To s1.Cells(65536, "d").End(xlUp).Row
    If WorksheetFunction.CountIf(s1.Range("a2:a" & x), s1.Cells(x, "a")) = 1 Then
    ComboBox2.AddItem Format(s1.Cells(x, "a").Value, "dd mmmm dddd")
    End If
    Next
    
    If ComboBox2.ListCount > 0 Then
    dizi = ComboBox2.List
    ComboBox2.Clear
    ComboBox2.List = sirala(dizi)
    ComboBox2.ListIndex = 0
[COLOR=red]    ComboBox3.Clear
    ComboBox3.List = sirala(dizi)
    ComboBox3.ListIndex = 0
[/COLOR]    End If
End Sub
 
Selamlar,

İlk olarak çalışmanıza bir adet ComboBox daha ekleyin. Muhtemelen adı ComboBox3 olacak. Eğer sizde farklı olursa aşağıdaki kodda kırmızı renkli bölümü ona göre değiştirin.

GÖSTER isimli butonunuza aşağıdaki kodu uygulayın.

Kod:
Private Sub CommandButton9_Click()
On Local Error Resume Next
t1 = CStr(ComboBox2.Value)
t2 = CStr([COLOR=red]ComboBox3.Value[/COLOR])
With ListBox1
    .ColumnCount = 8
    .Clear
    .RowSource = ""
    For i = 2 To Sheets("Sayfa2").Range("a65536").End(3).Row
        tarih = CStr(Format(Sheets("Sayfa2").Cells(i, 1).Value, "dd mmmm dddd"))
            If tarih >= t1 And tarih <= t2 Then
                .AddItem Format(Sheets("Sayfa2").Cells(i, 1).Value, "dd mmmm dddd")
                .List(ListBox1.ListCount - 1, 1) = Sheets("Sayfa2").Cells(i, 2).Value
                .List(ListBox1.ListCount - 1, 2) = Sheets("Sayfa2").Cells(i, 3).Value
                .List(ListBox1.ListCount - 1, 3) = Sheets("Sayfa2").Cells(i, 4).Value
                .List(ListBox1.ListCount - 1, 4) = Sheets("Sayfa2").Cells(i, 5).Value
                .List(ListBox1.ListCount - 1, 5) = Sheets("Sayfa2").Cells(i, 6).Value
                .List(ListBox1.ListCount - 1, 6) = Sheets("Sayfa2").Cells(i, 7).Value
            End If
    Next i
End With
CommandButton11_Click 'bu butona bas
End Sub


UserForm_Initialize kodunuzuda aşağıdaki ile değiştirin.

Kod:
Private Sub UserForm_Initialize()
    Dim X1 As Long, Y1 As Long, Y2 As Long, X2 As Long
    Dim CX As Double, CY As Double
    Dim MyCtrl As Control
        
        X1 = Application.Width
        Y1 = Application.Height
        X2 = Me.Width
        Y2 = Me.Height
        CX = X1 / X2
        CY = Y1 / Y2
        Me.Width = X1
        Me.Height = Y1
        For Each MyCtrl In Me.Controls
            MyCtrl.Top = MyCtrl.Top * CY
            MyCtrl.Left = MyCtrl.Left * CX
            MyCtrl.Width = MyCtrl.Width * CX
            MyCtrl.Height = MyCtrl.Height * CY
            On Error Resume Next
                MyCtrl.Font.Size = MyCtrl.Font.Size * CY
            On Error GoTo 0
        Next
    Sheets("Sayfa2").Activate
    Label6.Caption = Range("A1")
    Label7.Caption = Range("B1")
    Label8.Caption = Range("D1")
    Label9.Caption = Range("E1")
    Label10.Caption = Range("F1")
    Label11.Caption = Range("G1")
    ListBox1.ColumnCount = 8
    ListBox1.ColumnWidths = "100;160;0;85;85;85"
    ListBox1.ListIndex = ListBox1.ListCount - 1
    
    Sheets("sayfa2").Select
    
    Set s1 = Sheets("sayfa2")
    
    For x = 2 To s1.Cells(65536, "d").End(xlUp).Row
    If WorksheetFunction.CountIf(s1.Range("a2:a" & x), s1.Cells(x, "a")) = 1 Then
    ComboBox2.AddItem Format(s1.Cells(x, "a").Value, "dd mmmm dddd")
    End If
    Next
    
    If ComboBox2.ListCount > 0 Then
    dizi = ComboBox2.List
    ComboBox2.Clear
    ComboBox2.List = sirala(dizi)
    ComboBox2.ListIndex = 0
[COLOR=red]    ComboBox3.Clear
    ComboBox3.List = sirala(dizi)
    ComboBox3.ListIndex = 0
[/COLOR]    End If
End Sub

Çok teşekkür ederim .Allah sizden razı olsun..Ne kadar uğraşmıştım.Çok sağolun.
 
Korhan bey tekrar teşekkür ederim.Fikrinize sağlık.Çalışıyor. Lakin
" If tarih >= t1 And tarih <= t2 Then" bu kod ile 20 eylül tarihini 9 ekim den büyük sandığı için listelemiyor.Bunun için ne yapabiliriz?
 
Son düzenleme:
Geri
Üst