• DİKKAT

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

Soru Optionbutton hk.

Katılım
24 Ağustos 2021
Mesajlar
7
Excel Vers. ve Dili
Microsoft Office Professional Plus 2016
Merhaba, vba'ya yeni başladım ve işimi kolaylaştıracağını düşündüğüm bir çalışma için uğraşıyorum fakat bir yerde takıldım. Userform açarak frame üzerinde birden çok optionbutton ekledim ve hangisini seçersem excele o seçtiğim kısım 1 yazmasını istiyorum. Bir şeyler denedim fakat bir optionbuttonu seçtiğimde hepsinde 1 yazıyor. Nerede yanlış yaptığımı bir türlü çözemedim. Konu ile ilgili yardımcı olabilir misiniz?

---------------------------------------------------------------------------------------------------------------------------
Private Sub CommandButton1_Click()

Dim ws As Worksheet
Dim serviskutusu As Integer



Set ws = Sheets("SH_FITTINGS")

sonsatir = Cells(Rows.Count, "a").End(xlUp).Row + 1

If Me.OptionButton1 = True Then
serviskutusu = "1"
ElseIf Me.OptionButton2 = True Then
serviskutusu = "1"
ElseIf Me.OptionButton3 = True Then
serviskutusu = "1"
ElseIf Me.OptionButton4 = True Then
serviskutusu = "1"
ElseIf Me.OptionButton5 = True Then
serviskutusu = "1"
Else
End If

With ws
.Cells(sonsatir, 1) = Me.TextBox1.Text
.Cells(sonsatir, 2) = Me.TextBox2.Text
.Cells(sonsatir, 3) = serviskutusu
.Cells(sonsatir, 4) = serviskutusu
.Cells(sonsatir, 5) = serviskutusu
.Cells(sonsatir, 6) = serviskutusu
.Cells(sonsatir, 7) = serviskutusu
End With

Me.TextBox1 = vbNullString
Me.TextBox2 = vbNullString
Me.OptionButton1 = vbNullString
Me.OptionButton2 = vbNullString
Me.OptionButton3 = vbNullString
Me.OptionButton4 = vbNullString
Me.OptionButton5 = vbNullString


End Sub
 
>hangisini seçersem excele o seçtiğim kısım 1 yazmasını istiyorum.
Kodlarınız istediğiniz işlemi yapıyor, hangisini seçerseniz seçin serviskutusu'na 1 yazsın diye işlem yapıyor zaten.
 
Merhaba.
Deneyiniz.

Kod:
Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Set ws = Sheets("SH_FITTINGS")
    sonsatir = Cells(Rows.Count, "a").End(xlUp).Row + 1
    With ws
        If Me.OptionButton1 = True Then
            .Cells(sonsatir, 3) = 1
        ElseIf Me.OptionButton2 = True Then
            .Cells(sonsatir, 4) = 1
        ElseIf Me.OptionButton3 = True Then
            .Cells(sonsatir, 5) = 1
        ElseIf Me.OptionButton4 = True Then
            .Cells(sonsatir, 6) = 1
        ElseIf Me.OptionButton5 = True Then
            .Cells(sonsatir, 7) = 1
        End If
        .Cells(sonsatir, 1) = Me.TextBox1.Text
        .Cells(sonsatir, 2) = Me.TextBox2.Text
    End With
    Me.TextBox1 = vbNullString
    Me.TextBox2 = vbNullString
    Me.OptionButton1 = vbNullString
    Me.OptionButton2 = vbNullString
    Me.OptionButton3 = vbNullString
    Me.OptionButton4 = vbNullString
    Me.OptionButton5 = vbNullString
End Sub
 
Son düzenleme:
Merhaba.
Deneyiniz.

Kod:
Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Set ws = Sheets("SH_FITTINGS")
    sonsatir = Cells(Rows.Count, "a").End(xlUp).Row + 1
    If Me.OptionButton1 = True Then
        .Cells(sonsatir, 3) = 1
    ElseIf Me.OptionButton2 = True Then
        .Cells(sonsatir, 4) = 1
    ElseIf Me.OptionButton3 = True Then
        .Cells(sonsatir, 5) = 1
    ElseIf Me.OptionButton4 = True Then
        .Cells(sonsatir, 6) = 1
    ElseIf Me.OptionButton5 = True Then
        .Cells(sonsatir, 7) = 1
    Else
    End If
    With ws
        .Cells(sonsatir, 1) = Me.TextBox1.Text
        .Cells(sonsatir, 2) = Me.TextBox2.Text
    End With
    Me.TextBox1 = vbNullString
    Me.TextBox2 = vbNullString
    Me.OptionButton1 = vbNullString
    Me.OptionButton2 = vbNullString
    Me.OptionButton3 = vbNullString
    Me.OptionButton4 = vbNullString
    Me.OptionButton5 = vbNullString
End Sub

Merhaba Muzaffer Bey.
Kod hata veriyor.

Compile error:
İnvalid or unqualified reference
 
Hangi satıra gelince hata veriyor?
Dosyanızı da ekleyin ki hızlı, net ve doğru cevap alabilesiniz.
Dosyanızı dosya.tc gibi bir paylaşım sitesine ekleyebilirsiniz.
 
Teşekkür ederim Muzaffer Bey.

İyi çalışmalar.
 
Geri
Üst