• DİKKAT

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

Userform data tablosunun olmadıgı sayfada calısmıyor

Katılım
29 Mart 2013
Mesajlar
144
Excel Vers. ve Dili
office 2010
Ü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:D" & 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
 
Belgeyi ekledim

Yukarda tam anlatamadım sanırım kimse cvp yazmamıs.Bende excel isimli belgeyi ekledim. İstedigim su; Sayfa1 deki "Get Form" butonunu Sayfa2 ye kopyalayıp bu sayfada kullanmak ve özellikle tarih aralıgını secttigimiz iki kutucuk ve diger ozelliklerin faal olarak kullanılabilmesi icin kodlarda yapılacak degisiklik.Tesekkurler.

http://s6.dosya.tc/server8/l85thv/Excel.xls.html
 
bir Range nesnesinin önüne Sheet nesnesinin adı yazılmaz ise aktif olan sayfayı referans alır.

Kod:
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("Sayfa1").Range("A" & Rows.Count).End(xlUp).Row
        If CLng(CDate(Sheets("Sayfa1").Cells(i, 1).Value)) >= CLng(CDate(ComboBox1.Value)) And CLng(CDate(Sheets("Sayfa1").Cells(i, 1).Value)) <= CLng(CDate(ComboBox2.Value)) Then
            With ListBox1
                .AddItem Format(Sheets("Sayfa1").Cells(i, 1).Value, "dd.mm.yyyy")
                .List(.ListCount - 1, 1) = Sheets("Sayfa1").Cells(i, 2).Value
                .List(.ListCount - 1, 2) = Sheets("Sayfa1").Cells(i, 3).Value
                .List(.ListCount - 1, 3) = Sheets("Sayfa1").Cells(i, 4).Value
                .List(.ListCount - 1, 4) = Sheets("Sayfa1").Cells(i, 5).Value
                .List(.ListCount - 1, 5) = Format(Sheets("Sayfa1").Cells(i, 6).Value, "#,##0.00")
            End With
        End If
    Next i

End Sub

Private Sub UserForm_Initialize()

    Dim a As Variant, hcr As Range
    Dim pk As Worksheet
    
    Set pk = Sheets("Sayfa1")
    
    ListBox1.ColumnCount = 6
    ListBox1.ColumnWidths = "60,60,55,55,55,60"
    
    ComboBox1.Clear
    ComboBox2.Clear
    
    With Sheets("Sayfa1").Range("A2:D" & Sheets("Sayfa1").Cells(Rows.Count, 1).End(xlUp).Row)
        .Sort Key1:=Sheets("Sayfa1").Range("A2"), _
            Order1:=xlAscending, _
            Header:=xlYes, _
            OrderCustom:=1, _
            MatchCase:=False, _
            Orientation:=xlTopToBottom, _
            DataOption1:=xlSortTextAsNumbers
    End With
    
    
    With CreateObject("Scripting.Dictionary")
        For Each hcr In Sheets("Sayfa1").Range("A2:A" & Sheets("Sayfa1").Cells(Rows.Count, 1).End(xlUp).Row)
            If Not .exists(hcr.Value) Then
                .Add Format(hcr.Value, "dd.mm.yyyy"), Nothing
            End If
        Next hcr
        a = .keys
    End With

    ComboBox1.List = a
    ComboBox2.List = a

End Sub
 
Çok teşekkür ederim mancubus ümidi kesmiştim artık kimse cevap yazmadı diye çalıştı sayenizde öğrenicez bu işi
 
Geri
Üst