• DİKKAT

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

OptionButton tıklama olayı

Katılım
4 Aralık 2017
Mesajlar
117
Excel Vers. ve Dili
2010-2016 türkçe
Bir çalışmam var ve 50 küsür option butonum var veri yönetimi için kullanıyorum kaydet butonum var kaydete bastıgımda excelle kayıt ediyor ama kod çok uzun oldu bunu bir kısa yolu var mıdır acaba yardımlarınızı bekliyorum ? kodum şu şekilde
If OptionButton1.Value = True Then Cells(sonsat2, 11) = "B"
If OptionButton2.Value = True Then Cells(sonsat2, 11) = "X"
If OptionButton3.Value = True Then Cells(sonsat2, 13) = "B"
If OptionButton4.Value = True Then Cells(sonsat2, 13) = "X"
If OptionButton5.Value = True Then Cells(sonsat2, 15) = "B"
If OptionButton6.Value = True Then Cells(sonsat2, 15) = "X"
If OptionButton7.Value = True Then Cells(sonsat2, 17) = "B"
If OptionButton8.Value = True Then Cells(sonsat2, 17) = "X"
If OptionButton9.Value = True Then Cells(sonsat2, 19) = "B"
If OptionButton10.Value = True Then Cells(sonsat2, 19) = "X"
If OptionButton11.Value = True Then Cells(sonsat2, 21) = "B"
If OptionButton12.Value = True Then Cells(sonsat2, 21) = "X"
If OptionButton13.Value = True Then Cells(sonsat2, 23) = "B"
If OptionButton14.Value = True Then Cells(sonsat2, 23) = "X"
If OptionButton15.Value = True Then Cells(sonsat2, 25) = "B"
If OptionButton16.Value = True Then Cells(sonsat2, 25) = "X"
If OptionButton17.Value = True Then Cells(sonsat2, 27) = "B"
If OptionButton18.Value = True Then Cells(sonsat2, 27) = "X"
If OptionButton19.Value = True Then Cells(sonsat2, 29) = "B"
If OptionButton20.Value = True Then Cells(sonsat2, 29) = "X"
If OptionButton21.Value = True Then Cells(sonsat2, 31) = "B"
If OptionButton22.Value = True Then Cells(sonsat2, 31) = "X"
If OptionButton23.Value = True Then Cells(sonsat2, 33) = "B"
If OptionButton24.Value = True Then Cells(sonsat2, 33) = "X"
If OptionButton25.Value = True Then Cells(sonsat2, 35) = "B"
If OptionButton26.Value = True Then Cells(sonsat2, 35) = "X"
If OptionButton27.Value = True Then Cells(sonsat2, 37) = "B"
If OptionButton28.Value = True Then Cells(sonsat2, 37) = "X"
If OptionButton29.Value = True Then Cells(sonsat2, 39) = "B"
If OptionButton30.Value = True Then Cells(sonsat2, 39) = "X"
If OptionButton31.Value = True Then Cells(sonsat2, 41) = "B"
If OptionButton32.Value = True Then Cells(sonsat2, 41) = "X"
If OptionButton33.Value = True Then Cells(sonsat2, 43) = "B"
If OptionButton34.Value = True Then Cells(sonsat2, 43) = "X"
If OptionButton35.Value = True Then Cells(sonsat2, 45) = "B"
If OptionButton36.Value = True Then Cells(sonsat2, 45) = "X"
If OptionButton37.Value = True Then Cells(sonsat2, 47) = "B"
If OptionButton38.Value = True Then Cells(sonsat2, 47) = "X"
If OptionButton39.Value = True Then Cells(sonsat2, 49) = "B"
If OptionButton40.Value = True Then Cells(sonsat2, 49) = "X"
If OptionButton41.Value = True Then Cells(sonsat2, 51) = "B"
If OptionButton42.Value = True Then Cells(sonsat2, 51) = "X"
If OptionButton43.Value = True Then Cells(sonsat2, 53) = "B"
If OptionButton44.Value = True Then Cells(sonsat2, 53) = "X"
If OptionButton45.Value = True Then Cells(sonsat2, 55) = "B"
If OptionButton46.Value = True Then Cells(sonsat2, 55) = "X"
If OptionButton47.Value = True Then Cells(sonsat2, 57) = "B"
If OptionButton48.Value = True Then Cells(sonsat2, 57) = "X"
If OptionButton49.Value = True Then Cells(sonsat2, 59) = "B"
If OptionButton50.Value = True Then Cells(sonsat2, 59) = "X"
If OptionButton51.Value = True Then Cells(sonsat2, 61) = "B"
If OptionButton52.Value = True Then Cells(sonsat2, 61) = "X"
If OptionButton53.Value = True Then Cells(sonsat2, 63) = "B"
If OptionButton54.Value = True Then Cells(sonsat2, 63) = "X"
If OptionButton55.Value = True Then Cells(sonsat2, 65) = "B"
If OptionButton56.Value = True Then Cells(sonsat2, 65) = "X"
If OptionButton57.Value = True Then Cells(sonsat2, 67) = "B"
If OptionButton58.Value = True Then Cells(sonsat2, 67) = "X"
If OptionButton59.Value = True Then Cells(sonsat2, 69) = "B"
If OptionButton60.Value = True Then Cells(sonsat2, 69) = "X"
If OptionButton61.Value = True Then Cells(sonsat2, 71) = "B"
If OptionButton62.Value = True Then Cells(sonsat2, 71) = "X"
If OptionButton63.Value = True Then Cells(sonsat2, 73) = "B"
If OptionButton64.Value = True Then Cells(sonsat2, 73) = "X"
If OptionButton65.Value = True Then Cells(sonsat2, 75) = "B"
If OptionButton66.Value = True Then Cells(sonsat2, 75) = "X"
If OptionButton67.Value = True Then Cells(sonsat2, 77) = "B"
If OptionButton68.Value = True Then Cells(sonsat2, 77) = "X"
If OptionButton69.Value = True Then Cells(sonsat2, 79) = "B"
If OptionButton70.Value = True Then Cells(sonsat2, 79) = "X"
If OptionButton71.Value = True Then Cells(sonsat2, 81) = "B"
If OptionButton72.Value = True Then Cells(sonsat2, 81) = "X"
If OptionButton73.Value = True Then Cells(sonsat2, 83) = "B"
If OptionButton74.Value = True Then Cells(sonsat2, 83) = "X"
If OptionButton75.Value = True Then Cells(sonsat2, 85) = "B"
If OptionButton76.Value = True Then Cells(sonsat2, 85) = "X"
If OptionButton77.Value = True Then Cells(sonsat2, 87) = "B"
If OptionButton78.Value = True Then Cells(sonsat2, 87) = "X"
If OptionButton79.Value = True Then Cells(sonsat2, 89) = "B"
If OptionButton80.Value = True Then Cells(sonsat2, 89) = "X"
If OptionButton81.Value = True Then Cells(sonsat2, 91) = "B"
If OptionButton82.Value = True Then Cells(sonsat2, 91) = "X"
If OptionButton83.Value = True Then Cells(sonsat2, 93) = "B"
If OptionButton84.Value = True Then Cells(sonsat2, 93) = "X"
If OptionButton85.Value = True Then Cells(sonsat2, 95) = "B"
If OptionButton86.Value = True Then Cells(sonsat2, 95) = "X"
If OptionButton87.Value = True Then Cells(sonsat2, 97) = "B"
If OptionButton88.Value = True Then Cells(sonsat2, 97) = "X"
If OptionButton89.Value = True Then Cells(sonsat2, 99) = "B"
If OptionButton90.Value = True Then Cells(sonsat2, 99) = "X"
2 option buton bir frameyi oluşturuyor ikisinden birisi seçilip x ya da b yazdırıyor. her seferinde bu kadar uzun olmaması lazım diye düşünüyorum . Daha kısa satırla bu işi nasıl çözebilirim.şimdiden teşekkürler
 
Merhaba,

Bu şekilde deneyin.
Kod:
    For i = 1 To 90 Step 2
        If Controls("OptionButton" & i) = True Then Cells(sonsat2, i + 10) = "B"
        If Controls("OptionButton" & i + 1) = True Then Cells(sonsat2, i + 10) = "X"
    Next i
 
Hocam çok teşekkür ederim tam olarak istediğim şey buydu. Bunun bir de textbox lı hali var oda bayağı uzun onuda bu şekle nasıl çevirebiliriz. İşin içinden çıkamadım açıkçası yardımcı olursanız çok müteşekkir kalırım efendim.
kodum şu şekilde biraz amelece oldu ama :(
Cells(sonsat2, 2) = TextBox17
Cells(sonsat2, 3) = TextBox18
Cells(sonsat2, 4) = TextBox19
Cells(sonsat2, 5) = TextBox20
Cells(sonsat2, 6) = TextBox21
Cells(sonsat2, 7) = TextBox22
Cells(sonsat2, 8) = TextBox23
Cells(sonsat2, 9) = TextBox24

Cells(sonsat2, 10) = TextBox25
Cells(sonsat2, 12) = TextBox26
Cells(sonsat2, 14) = TextBox27
Cells(sonsat2, 16) = TextBox28
Cells(sonsat2, 18) = TextBox29
Cells(sonsat2, 20) = TextBox30
Cells(sonsat2, 22) = TextBox31
Cells(sonsat2, 24) = TextBox32
Cells(sonsat2, 26) = TextBox33
Cells(sonsat2, 28) = TextBox34
Cells(sonsat2, 30) = TextBox35
Cells(sonsat2, 32) = TextBox36
Cells(sonsat2, 34) = TextBox37
Cells(sonsat2, 36) = TextBox38
Cells(sonsat2, 38) = TextBox39
Cells(sonsat2, 40) = TextBox40
Cells(sonsat2, 42) = TextBox41
Cells(sonsat2, 44) = TextBox42
Cells(sonsat2, 46) = TextBox43
Cells(sonsat2, 48) = TextBox44
Cells(sonsat2, 50) = TextBox45
Cells(sonsat2, 52) = TextBox46
Cells(sonsat2, 54) = TextBox47
Cells(sonsat2, 56) = TextBox48
Cells(sonsat2, 58) = TextBox49
Cells(sonsat2, 60) = TextBox50
Cells(sonsat2, 62) = TextBox51
Cells(sonsat2, 64) = TextBox52
Cells(sonsat2, 66) = TextBox53
Cells(sonsat2, 68) = TextBox54
Cells(sonsat2, 70) = TextBox55
Cells(sonsat2, 72) = TextBox56
Cells(sonsat2, 74) = TextBox57
Cells(sonsat2, 76) = TextBox58
Cells(sonsat2, 78) = TextBox59
Cells(sonsat2, 80) = TextBox60
Cells(sonsat2, 82) = TextBox61
Cells(sonsat2, 84) = TextBox62
Cells(sonsat2, 86) = TextBox63
Cells(sonsat2, 88) = TextBox64
Cells(sonsat2, 90) = TextBox65
Cells(sonsat2, 92) = TextBox66
Cells(sonsat2, 94) = TextBox67
Cells(sonsat2, 96) = TextBox68
Cells(sonsat2, 98) = TextBox69
 
Son düzenleme:
Bu şekilde deneyin.
Kod:
    s = 2: a = 1
    For i = 17 To 69
        Cells(sonsat2, s) = Controls("TextBox" & i)
        If s >= 10 Then a = 2
        s = s + a
    Next i
 
Geri
Üst