• DİKKAT

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

Textbox karşınındaki CheckBox'sa göre kaydet

Merhaba,

If CheckBox1.Value = True Then
[A1] = Textbox1
End If

Gibi yazabilirsiniz.

.
 
İşaretli olanları alt alta yazarsak nasıl bir kod olur acaba
yani 3 veya 4 tane CheckBox işaretliyse
 
Aşağıdaki gibi bir yapı kurabilirsiniz.
Gerçek dosyanızda CheckBox1 sayısı kaç tane.
Eğer oldukça fazla ise, örnek dosyanızı eklerseniz daha pratik çözümler sunmamız kolaylaşır.
Örneğin CheckBox ve TextBox lar belli bir sayı sırası düzeninde ilerliyorsa döngü ile kodlar kısaltılabilir.

Kod:
Private Sub CommandButton1_Click()

    Dim son As Long
    
    son = Cells(Rows.Count, "A").End(xlUp).Row + 1
    If CheckBox1.Value = True Then
        Cells(son, "A") = TextBox1
        son = son + 1
    End If
    If CheckBox2.Value = True Then
        Cells(son, "A") = TextBox2
        son = son + 1
    End If
    If CheckBox3.Value = True Then
        Cells(son, "A") = TextBox3
        son = son + 1
    End If
    If CheckBox4.Value = True Then
        Cells(son, "A") = TextBox4
        son = son + 1
    End If
    If CheckBox5.Value = True Then
        Cells(son, "A") = TextBox5
        son = son + 1
    End If
    
End Sub

.
 
Teşekkürler Ömer bey
Son bir soru Row + 1 değerini Row + 2 yaptım 1 satır atlayarak kaydediyor arada geçen boş satırı dolgu rengi nasıl verebiliriz A ile F arası dolgu olması lazım

Kod:
  Dim son As Long
    
    son = Cells(Rows.Count, "A").End(xlUp).Row + 1
    If CheckBox1.Value = True Then
        Cells(son, "A") = TextBox1
        son = son + 1
    End If


Aşağıdaki gibi bir yapı kurabilirsiniz.
Gerçek dosyanızda CheckBox1 sayısı kaç tane.
Eğer oldukça fazla ise, örnek dosyanızı eklerseniz daha pratik çözümler sunmamız kolaylaşır.
Örneğin CheckBox ve TextBox lar belli bir sayı sırası düzeninde ilerliyorsa döngü ile kodlar kısaltılabilir.


Userformda
textbox1 textbox2 textbox3 CheckBox1
textbox4 textbox5 textbox6 CheckBox2
textbox7 textbox8 textbox9 CheckBox3 diye devam ediyor
 
Satır atlamadan yapmak için:

Kod:
Dim son As Long

Private Sub UserForm_Initialize()
    son = Cells(Rows.Count, "A").End(xlUp).Row + 1
[COLOR="DarkGreen"]    'UserForm_Initialize altında
    'farklı kodlarınız varsa bu bölüme ilave edersiniz.[/COLOR]
End Sub

Private Sub CommandButton1_Click()

    Dim sat As Long, i As Integer, j As Byte, chk_say As Integer

    chk_say = 5 [COLOR="darkgreen"]'5 yerini checkbox sayısı kaç ise onu yazarsınız[/COLOR]
    
    Range("A" & son & ":C" & son + chk_say - 1).ClearContents
    
    sat = son
    For i = 1 To chk_say
        If Controls("CheckBox" & i).Value = True Then
            For j = 1 To 3
                Cells(sat, j) = Controls("TextBox" & 3 * i + j - 3)
            Next j
            sat = sat + 1
        End If
    Next i
    
End Sub

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

Satır atlatıp renk eklemek için:

Kod:
Dim son As Long

Private Sub UserForm_Initialize()
    son = Cells(Rows.Count, "A").End(xlUp).Row + 2
    'UserForm_Initialize altında
    'farklı kodlarınız varsa bu bölüme ilave edersiniz.
End Sub

Private Sub CommandButton1_Click()

    Dim sat As Long, i As Integer, j As Byte, chk_say As Integer

    chk_say = 5 '5 yerini checkbox sayısı kaç ise onu yazarsınız
    
    Range("A" & son & ":C" & son + chk_say * 2 - 1).ClearContents
    Range("A" & son & ":F" & son + chk_say * 2 - 1).Interior.ColorIndex = 0
    
    sat = son
    For i = 1 To chk_say
        If Controls("CheckBox" & i).Value = True Then
            For j = 1 To 3
                Cells(sat, j) = Controls("TextBox" & 3 * i + j - 3)
            Next j
            Cells(sat + 1, "A").Resize(1, 6).Interior.ColorIndex = 8
            sat = sat + 2
        End If
    Next i
    
End Sub

.
 
Sayın Ömer Bey Çok Teşekkürler
 
Geri
Üst