Combobox2 de combobox1 e bağlı olan mahalli birimleri göstermek mümkünmü

Katılım
2 Mart 2005
Mesajlar
2,960
Excel Vers. ve Dili
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
excel sayfamız
B sütunu il adları>combobox1 de gösteriliyor
c sütunu ilçe adları> combobox1 te seçilen il adına göre b sütunu aranacak ve c sütunundaki ilçeleri comboboxta listelemek mümkünmü?
Kod:
Private Sub UserForm_Initialize()
Dim sfMB As Worksheet: Set sfMB = Sheets("ilveilce")
sonsat = sfMB.Cells(65536, "b").End(xlUp).Row
    For SUTB = 1 To sonsat
        If WorksheetFunction.CountIf(sfMB.Range("B1:B" & SUTB), sfMB.Range("B" & SUTB)) = 1 Then
            ComboBox1.AddItem sfMB.Cells(SUTB, "b").Value
        End If
    Next
End Sub
combobox1 için yukarıdaki kod kullanılmaktadır
 
Katılım
2 Mart 2005
Mesajlar
2,960
Excel Vers. ve Dili
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
MODUL
Kod:
Public sfMB As Worksheet
Public sonsat As Integer
Sub DegerAl()
Set sfMB = Sheets("ilveilce")
sonsat = sfMB.Cells(65536, "b").End(xlUp).Row
End Sub
USERFORM
Kod:
Private Sub UserForm_Initialize()
Call DegerAl
   For SUTB = 1 To sonsat
        If WorksheetFunction.CountIf(sfMB.Range("B1:B" & SUTB), sfMB.Range("B" & SUTB)) = 1 Then
            ComboBox1.AddItem sfMB.Cells(SUTB, "b").Value
        End If
    Next
End Sub

Private Sub ComboBox1_Change()
Call DegerAl
ilcebsl = WorksheetFunction.Match(ComboBox1.Value, sfMB.Range("B1:B" & sonsat), 0)
ilcebts = WorksheetFunction.Match(ComboBox1.Value, sfMB.Range("B1:B" & sonsat), 1)
MsgBox ilcebsl & " - " & ilcebts
'ComboBox2.RowSource = sfMB.Range("c" & ilcebsl & ":c" & ilcebts)
End Sub
istediğim bunun gibi ama ' satırda hata veriyor combobox1 değişince combombox2 de adana için c2:c14, edirne için c278:c285 listelenecek ama tıkandım
 
Katılım
2 Mart 2005
Mesajlar
2,960
Excel Vers. ve Dili
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
Sonunda hallettim...
USERFORM
Kod:
Private Sub ComboBox1_Change()
Call DegerAl
ilcebsl = WorksheetFunction.Match(ComboBox1.Value, sfMB.Range("B1:B" & sonsat), 0)
ilcebts = WorksheetFunction.Match(ComboBox1.Value, sfMB.Range("B1:B" & sonsat), 1)
'MsgBox ilcebsl & " - " & ilcebts
   ComboBox2.Clear
   For SUTC = ilcebsl To ilcebts
            ComboBox2.AddItem sfMB.Cells(SUTC, "C").Value
   Next
End Sub

Private Sub UserForm_Initialize()
Call DegerAl
   For SUTB = 1 To sonsat
        If WorksheetFunction.CountIf(sfMB.Range("B1:B" & SUTB), sfMB.Range("B" & SUTB)) = 1 Then
            ComboBox1.AddItem sfMB.Cells(SUTB, "b").Value
        End If
    Next
End Sub
Türkiye genelindeki İlçelere hangi mahalleler bağlıdır bu sorunun cevabını bilen varsa ksl msj ile ulaşabilir.
 

Korhan Ayhan

Administrator
Yönetici
Admin
Katılım
15 Mart 2005
Mesajlar
42,646
Excel Vers. ve Dili
Microsoft 365 Tr-En 64 Bit
Selamlar,

Konuyla ilgili örnek bir dosya hazırladım. Umarım faydası olur.
 
Katılım
2 Mart 2005
Mesajlar
2,960
Excel Vers. ve Dili
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
sayın costcontrol alakanıza teşekkür ederim
 
Katılım
14 Şubat 2006
Mesajlar
3,426
Excel Vers. ve Dili
(Excel 2016 - İngilizce)
Altın Üyelik Bitiş Tarihi
30-11-2022
Alternatif olarak aşağıdaki kodları inceleyiniz.

Kod:
Private Sub UserForm_Initialize()
Dim a, i
Set s1 = Sheets("ilveilce")
a = s1.Range("b2:b" & s1.[b65536].End(3).Row).Value
With CreateObject("Scripting.Dictionary")
    .CompareMode = vbTextCompare
    For i = 1 To UBound(a, 1)
        If Not IsEmpty(a(i, 1)) And Not .exists(a(i, 1)) Then .Add a(i, 1), Nothing
    Next
ComboBox1.Clear
ComboBox1.List = .keys
ComboBox1.ListIndex = 0
End With
Set s1 = Nothing
End Sub
 
Private Sub ComboBox1_Change()
Dim a, i
Set s1 = Sheets("ilveilce")
a = s1.Range("b2:c" & s1.[b65536].End(3).Row).Value
With CreateObject("Scripting.Dictionary")
    .CompareMode = vbTextCompare
    For i = 1 To UBound(a, 1)
        If a(i, 1) = ComboBox1.Value And Not .exists(a(i, 2)) Then .Add a(i, 2), Nothing
    Next
ComboBox2.Clear
ComboBox2.List = .keys
ComboBox2.ListIndex = 0
End With
Set s1 = Nothing
End Sub
 
Private Sub ComboBox2_Change()
Dim a, i
Set s1 = Sheets("ilveilce")
a = s1.Range("b2:d" & s1.[b65536].End(3).Row).Value
With CreateObject("Scripting.Dictionary")
    .CompareMode = vbTextCompare
    For i = 1 To UBound(a, 1)
        If a(i, 1) = ComboBox1.Value And a(i, 2) = ComboBox2.Value And Not .exists(a(i, 3)) Then .Add a(i, 3), Nothing
    Next
ComboBox3.Clear
ComboBox3.List = .keys
If ComboBox2.Value <> "" Then ComboBox3.ListIndex = 0
End With
Set s1 = Nothing
End Sub
&#214;zellikle fazla sat&#305;rl&#305; verilerde h&#305;zl&#305; &#231;al&#305;&#351;maktad&#305;r.
 
Katılım
2 Mart 2005
Mesajlar
2,960
Excel Vers. ve Dili
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
te&#351;ekk&#252;r ederim hocam
 
Katılım
2 Mart 2005
Mesajlar
2,960
Excel Vers. ve Dili
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
hocam bu olay&#305; ilveilce sayfas&#305;n&#305;n ad&#305;n&#305; data olarak de&#287;i&#351;tirdikten sonra ve ilveilceler.xls olarak kaydettikten sonra
form.xls yew ekleyece&#287;imiz userforma bu verileri getirmek i&#231;in ne yapmal&#305;y&#305;z
 
Üst