Listbox Üzerinde Toplama

walabi

Altın Üye
Katılım
22 Eylül 2012
Mesajlar
405
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Merhaba

Aşağıdaki kod bütün



Kod:
If TextBox1 <> "" Then
TextBox21 = Sheets("Barkod").Cells(Bul_2.Row, "C")
TextBox9 = WorksheetFunction.SumIfs(Sheets("Stok").Range("I:I"), Sheets("Stok").Range("G:G"), TextBox1.Value) - _
                WorksheetFunction.SumIfs(Sheets("Stok").Range("J:J"), Sheets("Stok").Range("G:G"), TextBox1.Value)

TextBox2 = Sheets("Barkod").Cells(Bul_2.Row, "B")
TextBox3 = Sheets("Barkod").Cells(Bul_2.Row, "C")
TextBox4 = 1
TextBox7 = Format(Replace(Sheets("Barkod").Cells(Bul_2.Row, "F"), ".", ","), "0.00") ' fiyat bilgisi olmadığında hata vermekte, düzeltilmeli
TextBox19 = Format(Replace(TextBox4 * TextBox7, ".", ","), "0.00")
TextBox17 = Sheets("Barkod").Cells(Bul_2.Row, "E")
TextBox18 = Format(Replace(TextBox19 - ((TextBox19 / (TextBox17 + 100)) * TextBox17), ".", ","), "0.00")
TextBox15 = Format(Replace((TextBox19 / (TextBox17 + 100)) * TextBox17, ".", ","), "0.00")
TextBox16 = 0
TextBox25 = 0
End If


If TextBox2.Value <> Empty And TextBox3.Value <> Empty And TextBox4.Value <> Empty And TextBox7.Value <> Empty Then
      
        With ListBox1
            .AddItem TextBox1.Text
            .List(.ListCount - 1, 0) = TextBox2.Value  ' barkod
            .List(.ListCount - 1, 1) = TextBox3.Value  ' ürün adı
            .List(.ListCount - 1, 2) = TextBox4.Value              ' satış adet
            .List(.ListCount - 1, 3) = Replace(TextBox7.Value, ".", ",") ' fiyat
            .List(.ListCount - 1, 4) = TextBox19.Value ' toplam fiyat
            .List(.ListCount - 1, 5) = TextBox17.Value ' kdv oranı
            .List(.ListCount - 1, 6) = TextBox18.Value ' Kdv matrah
            .List(.ListCount - 1, 7) = TextBox15.Value ' kdv tutar
            .List(.ListCount - 1, 8) = TextBox16.Value ' isk oran
            .List(.ListCount - 1, 9) = TextBox25.Value ' isk tutarı
         End With
        
        With ListBox2
            .AddItem
            .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
            .List(.ListCount - 1, 1) = TextBox11.Value ' firma
            .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
            .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
            .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
            .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
            .List(.ListCount - 1, 6) = TextBox2.Value ' Barkod
            .List(.ListCount - 1, 7) = TextBox3.Value ' Ürün Adı
            
        End With
End If
 

walabi

Altın Üye
Katılım
22 Eylül 2012
Mesajlar
405
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Merhaba

Aşağıdaki kod bütün



Kod:
If TextBox1 <> "" Then
TextBox21 = Sheets("Barkod").Cells(Bul_2.Row, "C")
TextBox9 = WorksheetFunction.SumIfs(Sheets("Stok").Range("I:I"), Sheets("Stok").Range("G:G"), TextBox1.Value) - _
                WorksheetFunction.SumIfs(Sheets("Stok").Range("J:J"), Sheets("Stok").Range("G:G"), TextBox1.Value)

TextBox2 = Sheets("Barkod").Cells(Bul_2.Row, "B")
TextBox3 = Sheets("Barkod").Cells(Bul_2.Row, "C")
TextBox4 = 1
TextBox7 = Format(Replace(Sheets("Barkod").Cells(Bul_2.Row, "F"), ".", ","), "0.00") ' fiyat bilgisi olmadığında hata vermekte, düzeltilmeli
TextBox19 = Format(Replace(TextBox4 * TextBox7, ".", ","), "0.00")
TextBox17 = Sheets("Barkod").Cells(Bul_2.Row, "E")
TextBox18 = Format(Replace(TextBox19 - ((TextBox19 / (TextBox17 + 100)) * TextBox17), ".", ","), "0.00")
TextBox15 = Format(Replace((TextBox19 / (TextBox17 + 100)) * TextBox17, ".", ","), "0.00")
TextBox16 = 0
TextBox25 = 0
End If


If TextBox2.Value <> Empty And TextBox3.Value <> Empty And TextBox4.Value <> Empty And TextBox7.Value <> Empty Then
     
        With ListBox1
            .AddItem TextBox1.Text
            .List(.ListCount - 1, 0) = TextBox2.Value  ' barkod
            .List(.ListCount - 1, 1) = TextBox3.Value  ' ürün adı
            .List(.ListCount - 1, 2) = TextBox4.Value              ' satış adet
            .List(.ListCount - 1, 3) = Replace(TextBox7.Value, ".", ",") ' fiyat
            .List(.ListCount - 1, 4) = TextBox19.Value ' toplam fiyat
            .List(.ListCount - 1, 5) = TextBox17.Value ' kdv oranı
            .List(.ListCount - 1, 6) = TextBox18.Value ' Kdv matrah
            .List(.ListCount - 1, 7) = TextBox15.Value ' kdv tutar
            .List(.ListCount - 1, 8) = TextBox16.Value ' isk oran
            .List(.ListCount - 1, 9) = TextBox25.Value ' isk tutarı
         End With
       
        With ListBox2
            .AddItem
            .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
            .List(.ListCount - 1, 1) = TextBox11.Value ' firma
            .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
            .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
            .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
            .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
            .List(.ListCount - 1, 6) = TextBox2.Value ' Barkod
            .List(.ListCount - 1, 7) = TextBox3.Value ' Ürün Adı
           
        End With
End If

Merhaba,

Ekli dosyada cntrl + m ile çalışan userform8 üzerinde textbox1 altında çalışan kodlar ile şunu yapmaktayım. Bir barkod okuyucu ile herhangi bir ürünün barkod numarasını okutup satış bilgilerini listbox1 e aktarmaktayım.

Textbox1 e veri girildikçe ( barkod numarası, örneğin 1001 gibi ) şunlar olmakta.
Textbox2 = barkod numarası
textbox3 = ürün adı
textbox4 = adet( her okutma için 1 adet anlamında)
textbox7 = satış fiyatı
Ve birkaç textbox daha yine bu olaya bağlı olarak sayısal değerler, hesaplamalar içermekte.

Textboxlara bu veriler işlendikten sonra ilgili veriler listbox1 e yüklenmekte.

İstediğim şey ise şu;

Bir ürün okuttuğumda listbox1 de alt alta sıralanmakta, aynı ürünü birden fazla okuttuğumda listbox1 de tek satırda nasıl toplayabilirim.
Sanırım bir döngü gerekli ama mantığını geliştiremedim açıkcası, ya da nasıl yapılabilir.

Örneğin 1001 kodunu textbox1 3 defa girdiğimde listbox1 de olan görünüm şu;
1001 - Defter - 1 - 10,25
1001 - Defter - 1 - 10,25
1001 - Defter - 1 - 10,25

Görmek istediğim sonuç ise şöyle;
1001 - Defter - 3 - 30,75

Aynı veri girişlerini tek bir satırda toplatmam gerekli. Nasıl yapılabilir?
 

Ekli dosyalar

YUSUF44

Destek Ekibi
Destek Ekibi
Katılım
4 Ocak 2006
Mesajlar
12,084
Excel Vers. ve Dili
İş : Ofis 365 - Türkçe
Ev: Ofis 365 - Türkçe
With ListBox1 satırından önce başka bir sorgu ve döngüyle kontrol yapılabilir:

PHP:
        If ListBox1.List(i, 0) = TextBox1.Value Then
            With ListBox1
                .List(i, 2) = .List(i, 2) + TextBox4.Value            ' satış adet
                .List(i, 4) = .List(i, 4) + TextBox19.Value ' toplam fiyat
            End With
        Else
            With ListBox1
                .AddItem TextBox1.Text
                .List(.ListCount - 1, 0) = TextBox2.Value  ' barkod
                .List(.ListCount - 1, 1) = TextBox3.Value  ' ürün adı
                .List(.ListCount - 1, 2) = TextBox4.Value              ' satış adet
                .List(.ListCount - 1, 3) = Replace(TextBox7.Value, ".", ",") ' fiyat
                .List(.ListCount - 1, 4) = TextBox19.Value ' toplam fiyat
                .List(.ListCount - 1, 5) = TextBox17.Value ' kdv oranı
                .List(.ListCount - 1, 6) = TextBox18.Value ' Kdv matrah
                .List(.ListCount - 1, 7) = TextBox15.Value ' kdv tutar
                .List(.ListCount - 1, 8) = TextBox16.Value ' isk oran
                .List(.ListCount - 1, 9) = TextBox25.Value ' isk tutarı
             End With
            
            With ListBox2
                .AddItem
                .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
                .List(.ListCount - 1, 1) = TextBox11.Value ' firma
                .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
                .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
                .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
                .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
                .List(.ListCount - 1, 6) = TextBox2.Value ' Barkod
                .List(.ListCount - 1, 7) = TextBox3.Value ' Ürün Adı
                
            End With
        End If
 

walabi

Altın Üye
Katılım
22 Eylül 2012
Mesajlar
405
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
With ListBox1 satırından önce başka bir sorgu ve döngüyle kontrol yapılabilir:

PHP:
        If ListBox1.List(i, 0) = TextBox1.Value Then
            With ListBox1
                .List(i, 2) = .List(i, 2) + TextBox4.Value            ' satış adet
                .List(i, 4) = .List(i, 4) + TextBox19.Value ' toplam fiyat
            End With
        Else
            With ListBox1
                .AddItem TextBox1.Text
                .List(.ListCount - 1, 0) = TextBox2.Value  ' barkod
                .List(.ListCount - 1, 1) = TextBox3.Value  ' ürün adı
                .List(.ListCount - 1, 2) = TextBox4.Value              ' satış adet
                .List(.ListCount - 1, 3) = Replace(TextBox7.Value, ".", ",") ' fiyat
                .List(.ListCount - 1, 4) = TextBox19.Value ' toplam fiyat
                .List(.ListCount - 1, 5) = TextBox17.Value ' kdv oranı
                .List(.ListCount - 1, 6) = TextBox18.Value ' Kdv matrah
                .List(.ListCount - 1, 7) = TextBox15.Value ' kdv tutar
                .List(.ListCount - 1, 8) = TextBox16.Value ' isk oran
                .List(.ListCount - 1, 9) = TextBox25.Value ' isk tutarı
             End With
           
            With ListBox2
                .AddItem
                .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
                .List(.ListCount - 1, 1) = TextBox11.Value ' firma
                .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
                .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
                .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
                .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
                .List(.ListCount - 1, 6) = TextBox2.Value ' Barkod
                .List(.ListCount - 1, 7) = TextBox3.Value ' Ürün Adı
               
            End With
        End If
Teşekkürler Yusuf bey
 

YUSUF44

Destek Ekibi
Destek Ekibi
Katılım
4 Ocak 2006
Mesajlar
12,084
Excel Vers. ve Dili
İş : Ofis 365 - Türkçe
Ev: Ofis 365 - Türkçe
Kurgu şöyle daha doğru oldu bence:

PHP:
If TextBox2.Value <> Empty And TextBox3.Value <> Empty And TextBox4.Value <> Empty And TextBox7.Value <> Empty Then
    For i = 0 To ListBox1.ListCount
        eski = "Yok"
        If ListBox1.List(i, 0) = TextBox1.Value Then
            With ListBox1
                .List(i, 2) = .List(i, 2) + TextBox4.Value            ' satış adet
                .List(i, 4) = .List(i, 4) + TextBox19.Value ' toplam fiyat
            End With
            eski = "Var"
            i = ListBox1.ListCount
        End If
    Next
    If eski = "Yok" Then
        With ListBox1
            .AddItem TextBox1.Text
            .List(.ListCount - 1, 0) = TextBox2.Value  ' barkod
            .List(.ListCount - 1, 1) = TextBox3.Value  ' ürün adı
            .List(.ListCount - 1, 2) = TextBox4.Value              ' satış adet
            .List(.ListCount - 1, 3) = Replace(TextBox7.Value, ".", ",") ' fiyat
            .List(.ListCount - 1, 4) = TextBox19.Value ' toplam fiyat
            .List(.ListCount - 1, 5) = TextBox17.Value ' kdv oranı
            .List(.ListCount - 1, 6) = TextBox18.Value ' Kdv matrah
            .List(.ListCount - 1, 7) = TextBox15.Value ' kdv tutar
            .List(.ListCount - 1, 8) = TextBox16.Value ' isk oran
            .List(.ListCount - 1, 9) = TextBox25.Value ' isk tutarı
         End With
        
        With ListBox2
            .AddItem
            .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
            .List(.ListCount - 1, 1) = TextBox11.Value ' firma
            .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
            .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
            .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
            .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
            .List(.ListCount - 1, 6) = TextBox2.Value ' Barkod
            .List(.ListCount - 1, 7) = TextBox3.Value ' Ürün Adı
            
        End With
    End If
End If
 

walabi

Altın Üye
Katılım
22 Eylül 2012
Mesajlar
405
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Kurgu şöyle daha doğru oldu bence:

PHP:
If TextBox2.Value <> Empty And TextBox3.Value <> Empty And TextBox4.Value <> Empty And TextBox7.Value <> Empty Then
    For i = 0 To ListBox1.ListCount
        eski = "Yok"
        If ListBox1.List(i, 0) = TextBox1.Value Then
            With ListBox1
                .List(i, 2) = .List(i, 2) + TextBox4.Value            ' satış adet
                .List(i, 4) = .List(i, 4) + TextBox19.Value ' toplam fiyat
            End With
            eski = "Var"
            i = ListBox1.ListCount
        End If
    Next
    If eski = "Yok" Then
        With ListBox1
            .AddItem TextBox1.Text
            .List(.ListCount - 1, 0) = TextBox2.Value  ' barkod
            .List(.ListCount - 1, 1) = TextBox3.Value  ' ürün adı
            .List(.ListCount - 1, 2) = TextBox4.Value              ' satış adet
            .List(.ListCount - 1, 3) = Replace(TextBox7.Value, ".", ",") ' fiyat
            .List(.ListCount - 1, 4) = TextBox19.Value ' toplam fiyat
            .List(.ListCount - 1, 5) = TextBox17.Value ' kdv oranı
            .List(.ListCount - 1, 6) = TextBox18.Value ' Kdv matrah
            .List(.ListCount - 1, 7) = TextBox15.Value ' kdv tutar
            .List(.ListCount - 1, 8) = TextBox16.Value ' isk oran
            .List(.ListCount - 1, 9) = TextBox25.Value ' isk tutarı
         End With
       
        With ListBox2
            .AddItem
            .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
            .List(.ListCount - 1, 1) = TextBox11.Value ' firma
            .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
            .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
            .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
            .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
            .List(.ListCount - 1, 6) = TextBox2.Value ' Barkod
            .List(.ListCount - 1, 7) = TextBox3.Value ' Ürün Adı
           
        End With
    End If
End If
Yusuf bey, şuan bilgisayar olmdığı için kontrol etme şansım yok, yarın yada pazartesi bakabilcem, mutlaka dönüş yapıcam.
 

walabi

Altın Üye
Katılım
22 Eylül 2012
Mesajlar
405
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Kurgu şöyle daha doğru oldu bence:

PHP:
If TextBox2.Value <> Empty And TextBox3.Value <> Empty And TextBox4.Value <> Empty And TextBox7.Value <> Empty Then
    For i = 0 To ListBox1.ListCount
        eski = "Yok"
        If ListBox1.List(i, 0) = TextBox1.Value Then
            With ListBox1
                .List(i, 2) = .List(i, 2) + TextBox4.Value            ' satış adet
                .List(i, 4) = .List(i, 4) + TextBox19.Value ' toplam fiyat
            End With
            eski = "Var"
            i = ListBox1.ListCount
        End If
    Next
    If eski = "Yok" Then
        With ListBox1
            .AddItem TextBox1.Text
            .List(.ListCount - 1, 0) = TextBox2.Value  ' barkod
            .List(.ListCount - 1, 1) = TextBox3.Value  ' ürün adı
            .List(.ListCount - 1, 2) = TextBox4.Value              ' satış adet
            .List(.ListCount - 1, 3) = Replace(TextBox7.Value, ".", ",") ' fiyat
            .List(.ListCount - 1, 4) = TextBox19.Value ' toplam fiyat
            .List(.ListCount - 1, 5) = TextBox17.Value ' kdv oranı
            .List(.ListCount - 1, 6) = TextBox18.Value ' Kdv matrah
            .List(.ListCount - 1, 7) = TextBox15.Value ' kdv tutar
            .List(.ListCount - 1, 8) = TextBox16.Value ' isk oran
            .List(.ListCount - 1, 9) = TextBox25.Value ' isk tutarı
         End With
       
        With ListBox2
            .AddItem
            .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
            .List(.ListCount - 1, 1) = TextBox11.Value ' firma
            .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
            .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
            .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
            .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
            .List(.ListCount - 1, 6) = TextBox2.Value ' Barkod
            .List(.ListCount - 1, 7) = TextBox3.Value ' Ürün Adı
           
        End With
    End If
End If
Kod:
    For i = 0 To ListBox1.ListCount - 1
        eski = "Yok"
        If ListBox1.List(i, 0) = TextBox1.Value Then
            With ListBox1
                .List(i, 2) = .List(i, 2) * 1 + TextBox4 * 1       ' satış adet
                .List(i, 4) = Format(Replace(.List(i, 4) * 1 + TextBox19 * 1, ".", ","), "#,##0.00")    'toplam fiyat
                .List(i, 6) = Format(Replace(.List(i, 6) * 1 + TextBox18 * 1, ".", ","), "#,##0.00")
                .List(i, 7) = Format(Replace(.List(i, 7) * 1 + TextBox15 * 1, ".", ","), "#,##0.00")
                .List(i, 9) = Format(Replace(.List(i, 9) * 1 + TextBox25 * 1, ".", ","), "#,##0.00")
            End With
        eski = "Var"
            i = ListBox1.ListCount - 1
        End If
    Next
    If eski = "Yok" Then
        With ListBox1
            .AddItem TextBox1.Text
            .List(.ListCount - 1, 0) = TextBox2                      ' barkod
            .List(.ListCount - 1, 1) = TextBox3                      ' ürün adı
            .List(.ListCount - 1, 2) = TextBox4                      ' satış adet
            .List(.ListCount - 1, 3) = Format(TextBox7, "#,##0.00")  ' fiyat    Replace(TextBox7.Value, ".", ",")
            .List(.ListCount - 1, 4) = Format(TextBox19, "#,##0.00") ' toplam fiyat
            .List(.ListCount - 1, 5) = TextBox17                     ' kdv oranı
            .List(.ListCount - 1, 6) = Format(TextBox18, "#,##0.00") ' Kdv matrah
            .List(.ListCount - 1, 7) = Format(TextBox15, "#,##0.00") ' kdv tutar
            .List(.ListCount - 1, 8) = TextBox16                     ' isk oran
            .List(.ListCount - 1, 9) = Format(TextBox25, "#,##0.00") ' isk tutarı
         End With
        
        With ListBox2
            .AddItem
            .List(.ListCount - 1, 0) = ComboBox1.Text  ' İşlem Türü
            .List(.ListCount - 1, 1) = TextBox11.Value ' firma
            .List(.ListCount - 1, 2) = TextBox12.Value ' vergi no
            .List(.ListCount - 1, 3) = TextBox13.Value ' tarih
            .List(.ListCount - 1, 4) = TextBox14.Value ' işlem no
            .List(.ListCount - 1, 5) = TextBox24.Value ' fatura no
            .List(.ListCount - 1, 6) = TextBox2.Value  ' Barkod
            .List(.ListCount - 1, 7) = TextBox3.Value  ' Ürün Adı
            
        End With
    End If
Yusuf bey, öncelikle teşekkürler,

İkinci mesajınızdaki kodları kendi dosyama uyarlayarak istediğim hale getirdim ve aradığım sonucu almaktayım. Ve dosya ektedir.

Yanlız kod satırları arasında ;

eski = "Yok"

eski = "Var"

şeklindeki ifadeler döngü ile nasıl bağlantı kurmakta bunu anlayamadım. Genelde eğer şöyle ise şöyle yap, değilse böyle yap, gibi mantıksal ifadelere aşinayım. Yani EĞER ifadesinden sonra herhangi bir ifadeyi başka bir ifadeyle kıyaslayarak ( büyük, eşit küçük vb ) formül kurmaya alıştığım için belirttiğim ifadeler tam olarak nasıl iş görmekte çözemedim.

Ya da kısaca anlatmak istediğim bu iki ifade kod satırları arasında kendi başlarına öylece duruyormuş gibi görünüyor bana göre. Ayrıca next den sonra i konulmamış, bu durumda hata almak gerekmiyor mu.

Mümkünse açıklayabilir misiniz.

Tekrardan teşekkürler,
 

Ekli dosyalar

YUSUF44

Destek Ekibi
Destek Ekibi
Katılım
4 Ocak 2006
Mesajlar
12,084
Excel Vers. ve Dili
İş : Ofis 365 - Türkçe
Ev: Ofis 365 - Türkçe
Eski="Yok" ifadesine dikkat ederseniz for next döngüsü içinde yer alıyor. Her i için ayrı ayrı kontrol yapılıyor. Önce listbox değeri textboxa eşit mi diye bakılıyor ve eski="var" oluyor ve buna göre işlem yapılıyor. Eğer txtbox ile listbox eşit değilse eski"yok olarak kalıyor ve ikinci işlem yani listbox'a ekleme işlemi yapılıyor. "Yok" olması için for next döngüsünün bitmesi yani tüm listbox değerlerinin kontrol edilmesi gerekiyor.
Eski="var" satırından sonra aramaya devam etmemesi için İ'ye listbox ın son satır numarası veriliyor ve for next döngüsü sonlanıyor.

Next i yazmaya gerek yok, kodlar hangi döngü de olduğunu biliyor. Muhtemelen birden fazla döngü içiçe kullanıldığında kod düzenini sağlamak ve hangisinin neyle ilgili olduğunu kolayca anlamak için next i vs kullanılıyordur.
 

YUSUF44

Destek Ekibi
Destek Ekibi
Katılım
4 Ocak 2006
Mesajlar
12,084
Excel Vers. ve Dili
İş : Ofis 365 - Türkçe
Ev: Ofis 365 - Türkçe
Dün telefondan yazdığımdan tam anlatamamış olabilirim.

Şimdi biz bir işlem yapacağız, eğer verimiz listede varsa üzerine toplayacağız, listede yoksa listeye ekleyeceğiz. Normalde sayfa üzerinde kontrol yaptığımızda EĞERSAY/ÇOKEĞERSAY formülleriyle belirlenen alanda aradığımız verinin olup olmadığını kontrol ediyoruz. VBA'daki karşılıkları COUNTIF/COUNTIFS. Ancak sizin dosyanızda kontrolü sayfa üzerinde değil de listboxtaki veriler üzerinden yapıyoruz. Denemedim ama muhtemelen lsitbox verileri üzerinde EĞERSAY formülü çalışmaz. bu nedenle aradığımız verinin listboxta olup olmadığını belirlemek için eski="yok" ve eski="var" yöntemini tercih ediyorum.

Burda kullandığım kelimelerin bir önemi yok, dosyada kullanılmayan ve VBA'nın kendi kodları arasıdna yer almayan herhangi bir şey kullanabiliriz. eski yerine abcd, "yok" yerine de "fdfdf" kullanmamızda sakınca yok yani. Anlaşılır olması için eski, var ve yok kelimelerini kullandım.

Listede olup olmamasına göre iki farklı işlem yapacağımızdan, değişkenimizi önce "yok" olarak tanımlıyoruz. Listeyi kontrole başlıyoruz, listede verimiz varsa değişkeni "var"a çeviriyoruz ve var olduğunda yapılması gereken işlemleri yaptırıyoruz. Kodun çalışması uzun sürmesin diye de for next döngüsünü sonlandırıyoruz.

Kodlarda sıradaki işlem listede aradığımız veri yoksa yapacağımız işlemler olduğundan kodda eski değişkeninin durumunu kontrol ettiriyoruz. eski değişkeni eğer "var" olarak değişmediyse aradığımız veri listede yok demektir. Bunu da if sorgusuyla kontrol ediyoruz, eğer eski değişkeni hala "yok" ise işlemleri yapıyoruz, "var" olarak değişmişse if sorgusu da sonlanıyor ve sonraki kod bloğuna geçiliyor.
 

walabi

Altın Üye
Katılım
22 Eylül 2012
Mesajlar
405
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Dün telefondan yazdığımdan tam anlatamamış olabilirim.

Şimdi biz bir işlem yapacağız, eğer verimiz listede varsa üzerine toplayacağız, listede yoksa listeye ekleyeceğiz. Normalde sayfa üzerinde kontrol yaptığımızda EĞERSAY/ÇOKEĞERSAY formülleriyle belirlenen alanda aradığımız verinin olup olmadığını kontrol ediyoruz. VBA'daki karşılıkları COUNTIF/COUNTIFS. Ancak sizin dosyanızda kontrolü sayfa üzerinde değil de listboxtaki veriler üzerinden yapıyoruz. Denemedim ama muhtemelen lsitbox verileri üzerinde EĞERSAY formülü çalışmaz. bu nedenle aradığımız verinin listboxta olup olmadığını belirlemek için eski="yok" ve eski="var" yöntemini tercih ediyorum.

Burda kullandığım kelimelerin bir önemi yok, dosyada kullanılmayan ve VBA'nın kendi kodları arasıdna yer almayan herhangi bir şey kullanabiliriz. eski yerine abcd, "yok" yerine de "fdfdf" kullanmamızda sakınca yok yani. Anlaşılır olması için eski, var ve yok kelimelerini kullandım.

Listede olup olmamasına göre iki farklı işlem yapacağımızdan, değişkenimizi önce "yok" olarak tanımlıyoruz. Listeyi kontrole başlıyoruz, listede verimiz varsa değişkeni "var"a çeviriyoruz ve var olduğunda yapılması gereken işlemleri yaptırıyoruz. Kodun çalışması uzun sürmesin diye de for next döngüsünü sonlandırıyoruz.

Kodlarda sıradaki işlem listede aradığımız veri yoksa yapacağımız işlemler olduğundan kodda eski değişkeninin durumunu kontrol ettiriyoruz. eski değişkeni eğer "var" olarak değişmediyse aradığımız veri listede yok demektir. Bunu da if sorgusuyla kontrol ediyoruz, eğer eski değişkeni hala "yok" ise işlemleri yapıyoruz, "var" olarak değişmişse if sorgusu da sonlanıyor ve sonraki kod bloğuna geçiliyor.
Yusuf bey teşekkürler, kodların ne işe yaradığını anlamıştım ancak textbox ya da combobox gibi bir ifadeye <, >, = gibi ifadelerle bağlı olmadığı için ilk başta garip gelmişti.

Ellerinize sağlık tekrardan,
 
Üst