DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
Altın Üyelik Hakkında Bilgi
Dim con As Object, rs As Object
Private Sub UserForm_Initialize()
Set con = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
con.Open "provider=microsoft.jet.oledb.4.0;data source = " & ThisWorkbook.FullName & _
";extended properties = ""excel 8.0;hdr=yes"""
rs.Open "select distinct(format(tarih,'dd.mm.yyyy')) from [Sayfa1$]", con, 1, 1
Do While Not rs.EOF
ComboBox1.AddItem rs.fields(0).Value
rs.movenext
Loop
rs.Close
End Sub
Private Sub ComboBox1_Change()
ComboBox1.Value = FormatDateTime(ComboBox1.Value, vbShortDate)
ComboBox2.Clear: ComboBox2.Text = Empty: TextBox1.Text = Empty
If rs.State = 1 Then rs.Close
rs.Open "select * from [Sayfa1$] where format(tarih,'dd.mm.yyyy') = '" & FormatDateTime(Me.ComboBox1.Value, vbShortDate) & "'", con, 1, 1
Do While Not rs.EOF
ComboBox2.AddItem rs.fields(1).Value
rs.movenext
Loop
End Sub
Private Sub ComboBox2_Change()
If ComboBox2.Text = Empty Then Exit Sub
If rs.State = 1 Then rs.Close
rs.Open "select * from [Sayfa1$] where format(tarih,'dd.mm.yyyy') = '" & FormatDateTime(Me.ComboBox1.Value, vbShortDate) & "' and kod='" & Me.ComboBox2.Text & "'", con, 1, 1
TextBox1.Text = rs.fields(2).Value
End Sub
text_yt = ""
If combo1 = "" Then
text_yt.RowSource = Empty: Exit Sub
End If
ilk = WorksheetFunction.Match(combo1, Sheets("Sheet2").[Q:Q], 0)
son = ilk - 1 + WorksheetFunction.CountIf(Sheets("Sheet2").[Q:Q], combo1)
text_yt.RowSource = "Sheet2!T" & ilk & ":T" & son
Private Sub UserForm_Initialize()
Dim Veri As Range, Liste As Collection
On Error Resume Next
ActiveWorkbook.RefreshAll
Set Liste = New Collection
For Each Veri In Sheets("Sheet2").Range("Q2:Q1000")
If Veri.Value <> "" Then Liste.Add Veri.Value, CStr(Veri.Value)
Next
For Each X In Liste
combo1.AddItem X
Next
End Sub
Private Sub combo1_Change()
Dim Veri As Range, Liste As Collection
On Error Resume Next
combo1 = Evaluate("=büyükharf(""" & combo1 & """)")
combo1 = Evaluate("=upper(""" & combo1 & """)")
Set Liste = New Collection
For Each Veri In Sheets("Sheet2").Range("Q2:Q1000")
If UCase(Replace(Replace(Veri.Value, "ı", "I"), "i", "İ")) = combo1 Then
Liste.Add Veri.Offset(0, 3).Value, CStr(Veri.Offset(0, 3).Value)
End If
Next
For Each X In Liste
text_yt.AddItem X
Next
End Sub
Private Sub text_yt_Change()
On Error Resume Next
text_yt = Evaluate("=büyükharf(""" & text_yt & """)")
text_yt = Evaluate("=upper(""" & text_yt & """)")
If ComboBox1 = "" Then
MsgBox ("Önce bölüm seçiniz!!!")
ComboBox1.SetFocus
End If
End Sub
Merhaba.
Mevcut UserForm kodlarını yazan kişi olmadığımdan diğer hususları gözden geçirmedim.
Anladığım kadarıyla Sheet2 isimli sayfada Q sütunundaki veriler sıralı durumda.
Bu sıralı olma durumundan hareketle; belirttiğiniz combo1 isimli Combobox nesnesine ait kodların
End Sub satırından önce aşağıdaki satırları eklerseniz istediğiniz olur.
Diğer nesne kodlarını da gözden geçirmeniz gerekebilir.
.Kod:text_yt = "" If combo1 = "" Then text_yt.RowSource = Empty: Exit Sub End If ilk = WorksheetFunction.Match(combo1, Sheets("Sheet2").[Q:Q], 0) son = ilk - 1 + WorksheetFunction.CountIf(Sheets("Sheet2").[Q:Q], combo1) text_yt.RowSource = "Sheet2!T" & ilk & ":T" & son
Eklediğiniz dosya benim notebookta garip bir şekilde yavaş çalışıyor. Uygulama yaptığım dosyanız da ektedir.
Ben alternatif olarak "Collection" özelliğini önerebilirim.
İlk olarak tasarım aşamasında "Combo1" nesnesinin "RowSource" özelliğindeki tanımlamayı temizleyin.
Formunuzun açılma olayını aşağıdaki gibi değiştirin.
Kod:Private Sub UserForm_Initialize() Dim Veri As Range, Liste As Collection On Error Resume Next ActiveWorkbook.RefreshAll Set Liste = New Collection For Each Veri In Sheets("Sheet2").Range("Q2:Q1000") If Veri.Value <> "" Then Liste.Add Veri.Value, CStr(Veri.Value) Next For Each X In Liste combo1.AddItem X Next End Sub
"Combo1" nesnesinin Change olayını aşağıdaki gibi değiştirin.
Kod:Private Sub combo1_Change() Dim Veri As Range, Liste As Collection On Error Resume Next combo1 = Evaluate("=büyükharf(""" & combo1 & """)") combo1 = Evaluate("=upper(""" & combo1 & """)") Set Liste = New Collection For Each Veri In Sheets("Sheet2").Range("Q2:Q1000") If UCase(Replace(Replace(Veri.Value, "ı", "I"), "i", "İ")) = combo1 Then Liste.Add Veri.Offset(0, 3).Value, CStr(Veri.Offset(0, 3).Value) End If Next For Each X In Liste text_yt.AddItem X Next End Sub
"text_yt" nesnesinin Change olayını aşağıdaki gibi değiştirin.
Kod:Private Sub text_yt_Change() On Error Resume Next text_yt = Evaluate("=büyükharf(""" & text_yt & """)") text_yt = Evaluate("=upper(""" & text_yt & """)") If ComboBox1 = "" Then MsgBox ("Önce bölüm seçiniz!!!") ComboBox1.SetFocus End If End Sub
Dosyanızı kayıt edip kapatıp açtıktan sonra denemeler yapın.