• DİKKAT

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

Mevcut Kod'a ilave çalışmadı

asdsxx

Altın Üye
Katılım
22 Mayıs 2012
Mesajlar
510
Excel Vers. ve Dili
Excel 2016 Türkçe
Sayın Ustalarım aşağıdaki kod'a ilave yaparak; şayet textbox'un müracak ettiği hücre boş ise bu boş hücreden önce aynı sütundaki ilk dolu hücredeki veriyi getirsin istiyorum

şu kodu ilave ettim ama çalışmadı.

Kod:
If veri2 = "" Then
For s = sat To sat - 20 Step -1
If Worksheets(sayf1).Cells(s, sut3).Value <> "" Then
veri2 = Worksheets(sayf1).Cells(s, sut3).Value
TextBox2.Text = veri2
Exit For
End If
Next s
Else
TextBox2.Text = veri2
End If

Bu kodu İlave olunmasını istediğim kod ise:

Kod:
Private Sub Combo2_Click()

If deg = 1 Then Exit Sub

'sayf1 = "data"
'ActiveSheet.Name
If CheckBox1.Value = True Then
ekle = ""
Else
ekle = Chr(10)
End If
sut2 = Combo2.ListIndex + sut9  '
veri2 = ""
TextBox2.Text = ""

If Lab2 = 1 Then
For j = 2 To Worksheets(sayf1).Cells(Rows.Count, sut6).End(3).Row
sayi9 = Len(ComboBox1.Text)
If Left(Worksheets(sayf1).Cells(j, sut6).Value, sayi9) = ComboBox1.Text Then

If Worksheets(sayf1).Cells(j, sut2).Value <> "" Then
If say = 0 Then
veri2 = Worksheets(sayf1).Cells(j, sut2).Value & ekle
Else
veri2 = veri2 & Chr(10) & Worksheets(sayf1).Cells(j, sut2).Value & ekle
End If
End If

say = say + 1
Else
son = j
If say > 1 Then Exit For
End If

Next j
TextBox2.Text = veri2
End If


If Lab2 = 2 Then
For j = 2 To Worksheets(sayf1).Cells(Rows.Count, sut6).End(3).Row
If Worksheets(sayf1).Cells(j, sut6).Value = ComboBox2.List(ComboBox2.ListIndex, 1) Then
If Worksheets(sayf1).Cells(j, sut2).Value <> "" Then
say5 = say5 + 1
If say5 = 1 Then Lab1 = j
say6 = say6 + 1
say5 = j
If say = 0 Then
veri2 = Worksheets(sayf1).Cells(j, sut2).Value & ekle
Else
veri2 = veri2 & Chr(10) & Worksheets(sayf1).Cells(j, sut2).Value & ekle
End If
End If


say = say + 1
Else
If say5 > 1 Then Exit For
End If
Next j
TextBox2.Text = veri2
End If

If Lab2 = 3 Then
sat = Val(ComboBox3.List(ComboBox3.ListIndex, 0))
sut2 = Combo2.ListIndex + sut9  '
TextBox2.Text = Sheets(sayf1).Cells(sat, sut2).Value
End If


If Lab2 = 4 Then
If ComboBox4.ListCount > 0 Then
sat = Val(ComboBox4.List(ComboBox4.ListIndex, 0))
sut2 = Combo2.ListIndex + sut9  '
TextBox2.Text = Sheets(sayf1).Cells(sat, sut2).Value
End If
End If

If Lab2 = 5 Then
If ComboBox5.ListCount > 0 Then
sat = Val(ComboBox5.List(ComboBox5.ListIndex, 0))
sut2 = Combo2.ListIndex + sut9  '
TextBox2.Text = Sheets(sayf1).Cells(sat, sut2).Value
End If
End If

If Lab2 = 6 Then
For j = 2 To Worksheets(sayf1).Cells(Rows.Count, sut6).End(3).Row
sayi9 = Len(ComboBox6.Text)
If Left(Worksheets(sayf1).Cells(j, sut6).Value, sayi9) = ComboBox6.Text Then

If Worksheets(sayf1).Cells(j, sut2).Value <> "" Then
If say = 0 Then
veri2 = Worksheets(sayf1).Cells(j, sut2).Value & ekle
Else
veri2 = veri2 & Chr(10) & Worksheets(sayf1).Cells(j, sut2).Value & ekle
End If
End If

say = say + 1
Else
son = j
If say > 1 Then Exit For
End If

Next j
TextBox2.Text = veri2
End If

If Lab2 = 7 Then
For j = 2 To Worksheets(sayf1).Cells(Rows.Count, sut6).End(3).Row
sayi9 = Len(ComboBox7.Text)
If Left(Worksheets(sayf1).Cells(j, sut6).Value, sayi9) = ComboBox7.Text Then

If Worksheets(sayf1).Cells(j, sut2).Value <> "" Then
If say = 0 Then
veri2 = Worksheets(sayf1).Cells(j, sut2).Value & ekle
Else
veri2 = veri2 & Chr(10) & Worksheets(sayf1).Cells(j, sut2).Value & ekle
End If
End If

say = say + 1
Else
son = j
If say > 1 Then Exit For
End If

Next j
TextBox2.Text = veri2
End If
 
TextBox2.SetFocus
TextBox2.CurLine = 0
End Sub
 
Basit mantıkla aşağıdaki gibi olabilir.

Kendi kodlarınıza adapte edersiniz.

C++:
Private Sub CommandButton1_Click()
    If Range("C10") = "" Then
        TextBox1 = Range("C2:C1000").Find("?").Value
    End If
End Sub

Kod C10 hücrene bakar boş ise C2:C1000 aralığındaki ilk hücredeki veriyi getirir.
 
Basit mantıkla aşağıdaki gibi olabilir.

Kendi kodlarınıza adapte edersiniz.

C++:
Private Sub CommandButton1_Click()
    If Range("C10") = "" Then
        TextBox1 = Range("C2:C1000").Find("?").Value
    End If
End Sub

Kod C10 hücrene bakar boş ise C2:C1000 aralığındaki ilk hücredeki veriyi getirir.

Korhan Bey ilginize teşekkürler. Ama benim anlatmak istediğim olay "Combo2" Combobox dan veri seçince, o verinin adresindeki hücre boş ise kendinden önceki ilk dolu hücredeki veriyi getirmesi
Yani sütun ve hücre aralığı sabit değil değişken

Kod:
If veri2 = "" Then
For s = sat To sat - 20 Step -1
If Worksheets(sayf1).Cells(s, sut3).Value <> "" Then
veri2 = Worksheets(sayf1).Cells(s, sut3).Value
TextBox2.Text = veri2
Exit For
End If
Next s
Else
TextBox2.Text = veri2
End If

Bu kod aslında farklı bir ComboBox nesnesinde çalışıyor. Bu kodu Yukarıda verdiğim "Combo2" kod grubuna nasıl ekleyebilirim
 
VB edit çalışabilirseniz çok kolay olduğunu göreceksiniz.:cool:
 
Ben zaten olayın mantığı için örnek verdim. Uyarlama işi size kalmış..
 
Pes etmeyin..

Kodu F8 tuşu ile adım adım çalıştırıp adımları izleyin.

O zaman daha kolay çözüm üretebilirsiniz.
 
Geri
Üst