Üstatlar yine bir konuda tıkandım. Sayfa1 de data tablom var bu tablodan iki tarih arası filtreleme olusturan UserForm2 olusturdum.Sayfa 2 ye buton olusturdum userform2 i acıyorum ancak tarih sectigim acılan 2 listbox bos görünüyor. Eger butonu Sayfa1 e koyup asagıdaki kodlardan ikisini Sayfa1 olarak duzeltirsem listbox dolu gorünuyor.Kisaca asagıdaki kodu veri tablosunun olmadıgı sayfa2 den calıstırınca sayfa1 deki veri tablosundan tarih kısmından veri cekerek listboxun dolu olacak sekilde asagıdaki kodların düzenlenmesi gerekiyor.Not:Rowsource kısmina tanımlanan sütün adı yazılınca olmadı.
Private Sub CommandButton1_Click()
Dim i As Long
If ComboBox1.Value = "" Or ComboBox2.Value = "" Then
MsgBox "Please Choose Date", vbCritical, ""
Exit Sub
End If
Label1.Caption = ComboBox1.Value
Label2.Caption = ComboBox2.Value
ListBox1.Clear
For i = 2 To Sheets("Sayfa2").Range("a65536").End(3).Row
If VBA.CLng(VBA.CDate(Cells(i, "c").Value)) >= VBA.CLng(VBA.CDate(ComboBox1.Value)) And VBA.CLng(VBA.CDate(Cells(i, "c").Value)) <= VBA.CLng(VBA.CDate(ComboBox2.Value)) Then
With ListBox1
.AddItem VBA.Format(Cells(i, 3).Value, "dd.mm.yyyy")
.List(.ListCount - 1, 1) = Cells(i, 2).Value
.List(.ListCount - 1, 2) = Cells(i, 4).Value
.List(.ListCount - 1, 3) = Cells(i, 5).Value
.List(.ListCount - 1, 4) = Cells(i, 6).Value
.List(.ListCount - 1, 5) = Cells(i, 7).Value
.List(.ListCount - 1, 6) = Cells(i, 8).Value
.List(.ListCount - 1, 7) = Cells(i, 9).Value
.List(.ListCount - 1, 8) = VBA.Format(Cells(i, 10).Value, "#,##0.00")
End With
End If
Next i
i = Empty
End Sub
Private Sub UserForm_Initialize()
Dim c As Variant, hcr As Range
Dim pk As Worksheet
ListBox1.ColumnCount = 8
ListBox1.ColumnWidths = "60,60,55,55,55,60,55,55"
ComboBox1.Clear
ComboBox2.Clear
Set pk = Sheets("Sayfa2")
With pk.Range("A2
" & Cells(Rows.Count, "A").End(xlUp).Row)
.Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End With
With CreateObject("Scripting.Dictionary")
For Each hcr In pk.Range("C2:C" & pk.Cells(65536, "C").End(xlUp).Row)
If Not .exists(hcr.Value) Then
.Add VBA.Format(hcr.Value, "dd.mm.yyyy"), Nothing
End If
Next hcr
c = .keys
End With
ComboBox1.List = c
ComboBox2.List = c
End Sub
Private Sub CommandButton1_Click()
Dim i As Long
If ComboBox1.Value = "" Or ComboBox2.Value = "" Then
MsgBox "Please Choose Date", vbCritical, ""
Exit Sub
End If
Label1.Caption = ComboBox1.Value
Label2.Caption = ComboBox2.Value
ListBox1.Clear
For i = 2 To Sheets("Sayfa2").Range("a65536").End(3).Row
If VBA.CLng(VBA.CDate(Cells(i, "c").Value)) >= VBA.CLng(VBA.CDate(ComboBox1.Value)) And VBA.CLng(VBA.CDate(Cells(i, "c").Value)) <= VBA.CLng(VBA.CDate(ComboBox2.Value)) Then
With ListBox1
.AddItem VBA.Format(Cells(i, 3).Value, "dd.mm.yyyy")
.List(.ListCount - 1, 1) = Cells(i, 2).Value
.List(.ListCount - 1, 2) = Cells(i, 4).Value
.List(.ListCount - 1, 3) = Cells(i, 5).Value
.List(.ListCount - 1, 4) = Cells(i, 6).Value
.List(.ListCount - 1, 5) = Cells(i, 7).Value
.List(.ListCount - 1, 6) = Cells(i, 8).Value
.List(.ListCount - 1, 7) = Cells(i, 9).Value
.List(.ListCount - 1, 8) = VBA.Format(Cells(i, 10).Value, "#,##0.00")
End With
End If
Next i
i = Empty
End Sub
Private Sub UserForm_Initialize()
Dim c As Variant, hcr As Range
Dim pk As Worksheet
ListBox1.ColumnCount = 8
ListBox1.ColumnWidths = "60,60,55,55,55,60,55,55"
ComboBox1.Clear
ComboBox2.Clear
Set pk = Sheets("Sayfa2")
With pk.Range("A2
.Sort Key1:=Range("A2"), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End With
With CreateObject("Scripting.Dictionary")
For Each hcr In pk.Range("C2:C" & pk.Cells(65536, "C").End(xlUp).Row)
If Not .exists(hcr.Value) Then
.Add VBA.Format(hcr.Value, "dd.mm.yyyy"), Nothing
End If
Next hcr
c = .keys
End With
ComboBox1.List = c
ComboBox2.List = c
End Sub
