Bir userformun belirli bir satırındaki kodu başka bir userformda kullanmak için kullanılacak kod nedir ?

Katılım
4 Mart 2013
Mesajlar
14
Excel Vers. ve Dili
Microsoft 2010
Diyelim elimizde userform1 de belirli satırlar arasında bir kod bloğu var 20 satırlık ve siz bu 20 satırlık kodu her açacağınız yeni userform sayfasında kullanacaksınız bunu açacağınız her userform sayfasında kullanmanın pratik yolu nedir acaba ? özetle normalde asp de olan incude mantığı var mı vba da daha çok çok yeniyim lütfen sorduğum soru tuhafsa kusuruma bakmayın. Bir kod bloğu yazdım for döngüleri kullanmadağım için koda satır sayım fazla olduğundan bana procedure too large hatası alıyorum. Kodları azaltmam lazım call ile denedim olmadı veya ben beceremedim.

Aşağıdaki bloğu daha kısa yazmanın yolu var mıdır ? bu bloğu her sayfada nasıl kullanabilir hale geitrebilirim ?



Private Sub CommandButton2_Click()

If ComboBox10.Value = "1" Then Sheets("1").Range("e34" & Bos_Satir).Value = Sheets("1").[e34] + TextBox7.Value
If ComboBox10.Value = "2" Then Sheets("2").Range("e34" & Bos_Satir).Value = Sheets("2").[e34] + TextBox7.Value
If ComboBox10.Value = "3" Then Sheets("3").Range("e34" & Bos_Satir).Value = Sheets("3").[e34] + TextBox7.Value
If ComboBox10.Value = "4" Then Sheets("4").Range("e34" & Bos_Satir).Value = Sheets("4").[e34] + TextBox7.Value
If ComboBox10.Value = "5" Then Sheets("5").Range("e34" & Bos_Satir).Value = Sheets("5").[e34] + TextBox7.Value
If ComboBox10.Value = "6" Then Sheets("6").Range("e34" & Bos_Satir).Value = Sheets("6").[e34] + TextBox7.Value
If ComboBox10.Value = "7" Then Sheets("7").Range("e34" & Bos_Satir).Value = Sheets("7").[e34] + TextBox7.Value
If ComboBox10.Value = "8" Then Sheets("8").Range("e34" & Bos_Satir).Value = Sheets("8").[e34] + TextBox7.Value
If ComboBox10.Value = "9" Then Sheets("9").Range("e34" & Bos_Satir).Value = Sheets("9").[e34] + TextBox7.Value
If ComboBox10.Value = "10" Then Sheets("10").Range("e34" & Bos_Satir).Value = Sheets("10").[e34] + TextBox7.Value
If ComboBox10.Value = "11" Then Sheets("11").Range("e34" & Bos_Satir).Value = Sheets("11").[e34] + TextBox7.Value
If ComboBox10.Value = "12" Then Sheets("12").Range("e34" & Bos_Satir).Value = Sheets("12").[e34] + TextBox7.Value
If ComboBox10.Value = "13" Then Sheets("13").Range("e34" & Bos_Satir).Value = Sheets("13").[e34] + TextBox7.Value
If ComboBox10.Value = "14" Then Sheets("14").Range("e34" & Bos_Satir).Value = Sheets("14").[e34] + TextBox7.Value
If ComboBox10.Value = "15" Then Sheets("15").Range("e34" & Bos_Satir).Value = Sheets("15").[e34] + TextBox7.Value
If ComboBox10.Value = "16" Then Sheets("16").Range("e34" & Bos_Satir).Value = Sheets("16").[e34] + TextBox7.Value
If ComboBox10.Value = "17" Then Sheets("17").Range("e34" & Bos_Satir).Value = Sheets("17").[e34] + TextBox7.Value
If ComboBox10.Value = "18" Then Sheets("18").Range("e34" & Bos_Satir).Value = Sheets("18").[e34] + TextBox7.Value
If ComboBox10.Value = "19" Then Sheets("19").Range("e34" & Bos_Satir).Value = Sheets("19").[e34] + TextBox7.Value
If ComboBox10.Value = "20" Then Sheets("20").Range("e34" & Bos_Satir).Value = Sheets("20").[e34] + TextBox7.Value
If ComboBox10.Value = "21" Then Sheets("21").Range("e34" & Bos_Satir).Value = Sheets("21").[e34] + TextBox7.Value
If ComboBox10.Value = "22" Then Sheets("22").Range("e34" & Bos_Satir).Value = Sheets("22").[e34] + TextBox7.Value
If ComboBox10.Value = "23" Then Sheets("23").Range("e34" & Bos_Satir).Value = Sheets("23").[e34] + TextBox7.Value
If ComboBox10.Value = "24" Then Sheets("24").Range("e34" & Bos_Satir).Value = Sheets("24").[e34] + TextBox7.Value
If ComboBox10.Value = "25" Then Sheets("25").Range("e34" & Bos_Satir).Value = Sheets("25").[e34] + TextBox7.Value
If ComboBox10.Value = "26" Then Sheets("26").Range("e34" & Bos_Satir).Value = Sheets("26").[e34] + TextBox7.Value
If ComboBox10.Value = "27" Then Sheets("27").Range("e34" & Bos_Satir).Value = Sheets("27").[e34] + TextBox7.Value
If ComboBox10.Value = "28" Then Sheets("28").Range("e34" & Bos_Satir).Value = Sheets("28").[e34] + TextBox7.Value
If ComboBox10.Value = "29" Then Sheets("29").Range("e34" & Bos_Satir).Value = Sheets("29").[e34] + TextBox7.Value
If ComboBox10.Value = "30" Then Sheets("30").Range("e34" & Bos_Satir).Value = Sheets("30").[e34] + TextBox7.Value
If ComboBox10.Value = "31" Then Sheets("31").Range("e34" & Bos_Satir).Value = Sheets("31").[e34] + TextBox7.Value
 

Muzaffer Ali

Destek Ekibi
Destek Ekibi
Katılım
5 Haziran 2006
Mesajlar
5,806
Excel Vers. ve Dili
2019 Türkçe
Merhaba.

Yukarıdaki tüm satırları silip yerine sadece aşağıdaki şekilde aynı işlemi yapabilirsiniz.

Kod:
Private Sub CommandButton2_Click()
    Sheets("""" & ComboBox10.Value & """").Range("e34" & Bos_Satir).Value = Sheets("""" & ComboBox10.Value & """").[e34] + TextBox7.Value
End Sub
 
Katılım
4 Mart 2013
Mesajlar
14
Excel Vers. ve Dili
Microsoft 2010
Teşekkür ederim ama olmadı burada combobox10 da seçilen sayfanın (31 adet sayfa var hangi seçilirse) e34 hücresine textbox7 de yazılan tutarı e34 hücresindeki değerle toplayıp yazdırmaya çalışıyordum.

Combobox1 da oluşturduğum 31 adet sayfaya hangi sayfa seçilmişse hepsinde e34 hücresindeki değerin üzerine textbox 7 yi toplatıp yazdırıyordum.
 

Korhan Ayhan

Administrator
Yönetici
Admin
Katılım
15 Mart 2005
Mesajlar
41,454
Excel Vers. ve Dili
Microsoft 365 Tr-En 64 Bit
Merhaba,

Acilen kodlarınızı kısaltmanızı tavsiye ederim. Yoksa dosyanızda çalışamaz hale gelebilirsiniz.

Genellikle UserForm üzerinde kullanılacak nesnelerde ortak bir kod yapısı kullanılacaksa fonksiyon yazarak çözüme gidebilirsiniz. Ya da Class Module uygulaması ile nesnelere ortak özellik kazandırabilirsiniz.

Çok satırdan oluşan kod yapılarınızı döngüler şekline dönüştürürseniz okumanızda kolaylaşacaktır.
 

Muzaffer Ali

Destek Ekibi
Destek Ekibi
Katılım
5 Haziran 2006
Mesajlar
5,806
Excel Vers. ve Dili
2019 Türkçe
Şimdi fark ettim Bos_Satir diye bir değişken var sorun bundan kaynaklanıyor olabilir.
Aşağıdaki kodu deneyin hem biraz daha kısalttım.

Neyin olmadığını, hata ise nasıl bir hata aldığınızı gibi açıklamalar yapın ki sorunu bulabilelim.
Eğer yine de olmuyorsa. Dosyanızı dosya.tc gibi bir paylaşım sitesine ekleyin kontrol edelim.

Kod:
Private Sub CommandButton2_Click()
    With Sheets("""" & ComboBox10.Value & """")
        .Range("E34") = .Range("E34") + TextBox7.Value
    End With
End Sub
 
Katılım
4 Mart 2013
Mesajlar
14
Excel Vers. ve Dili
Microsoft 2010
Kodlarım yeni başladığım için kısa yazılabilecekken çok uzun yazılmış olmasından kaynaklanıyor. amatör bir yazım olduğunu düşünerek yardımcı olursanız mutlu olurum. İlgi hatayı aldığım userform109 no lu sayfanın kodlarını aşağıdaki linkteki dosyama attım.

 

Muzaffer Ali

Destek Ekibi
Destek Ekibi
Katılım
5 Haziran 2006
Mesajlar
5,806
Excel Vers. ve Dili
2019 Türkçe
Dosya indirilemiyor.
Bu şekilde değil de dosyanızı ekleseniz daha hızlı ve doğru cevap alırsınız.
Dosyanızda özel bilgiler varsa bir kopyasını alıp özel bilgileri gerçekçi başka değerlerle değiştirebilirsiniz.
 
Katılım
4 Mart 2013
Mesajlar
14
Excel Vers. ve Dili
Microsoft 2010
Yardımlar için teşekkürler call ile kodları kümelere ayırıp çağırdım sorun çözüldü
 
Üst