• DİKKAT

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

Tekrarlanan kodların tek hale getirilmesi

  • Konbuyu başlatan Konbuyu başlatan hsayar
  • Başlangıç tarihi Başlangıç tarihi
Katılım
2 Mart 2005
Mesajlar
2,960
Excel Vers. ve Dili
ev: Ofis 2007- Win Xp
iş: Ofis 2010- Win Vista
Kod:
....
...
...
    '12+V>>>>>>>>>>
    ElseIf s1.Cells(g, 1) = "12" And (s1.Cells(g, 2) = "V" Or s1.Cells(g, 2) = "v") Then
    c = c + 1
        'ikinci sütun kontrolü
        If c = 35 Then
        sut = 6: c = 1
        End If
        'ev stok Kayıt sayısı kontrolü
        If WorksheetFunction.CountA(s2.[e11:e44,k11:k44]) = 68 Then
        MsgBox "Tablo dolduğu için kayıt yapılamadı.", , "UYARI": Exit Sub
        End If
    '12 lik stok çıkış yazma işlemi
    s2.Cells(c + 10, 1 + sut) = s1.Cells(g, 5)
        s2.Select: Cells(c + 10, 1 + sut).Select
        Selection.Font.ColorIndex = 2
        Selection.Interior.ColorIndex = 1
        Selection.Font.Bold = True ''seçili hücreyi siyah dolgu,beyaz kalın yaz
    s2.Cells(c + 10, 2 + sut) = UCase(s1.Cells(g, 4))
        s2.Select: Cells(c + 10, 2 + sut).Select
        Selection.Font.ColorIndex = 2
        Selection.Interior.ColorIndex = 1
        Selection.Font.Bold = True ''seçili hücreyi siyah dolgu,beyaz kalın yaz
    s2.Cells(c + 10, 5 + sut) = s1.Cells(g, 7)
        s2.Select: Cells(c + 10, 5 + sut).Select
        Selection.Font.ColorIndex = 2
        Selection.Interior.ColorIndex = 1
        Selection.Font.Bold = True ''seçili hücreyi siyah dolgu,beyaz kalın yaz
    
    '<<<<<<<<<<<<<<<<<12+V
    End If
....
....
....

yukarıdaki kodlarda (seçili hücreyi siyah dolgu,beyaz kalın yaz) işlemi her koşul gerçekleştirildiğinde yapılyor bunu ensonda bir kodda yazmak nasıl olur?

Saygılarımla
 
Merhabalar,

Ko&#351;ul ger&#231;ekle&#351;ti&#287;inde yap&#305;l&#305;yor ise, en sondan kast&#305;n&#305;z nedir?

E&#287;er End If'ten sonra ise; bu durumda ko&#351;ul ger&#231;ekle&#351;se de ger&#231;ekle&#351;mese de se&#231;ili h&#252;cre siyah dolgulu ve beyaz-kal&#305;n olur?
 
say&#305;n fpc kast&#305;m &#351;u bu bi&#231;imlendirmeyi yapmak i&#231;in 12 sat&#305;rr harc&#305;yoruz;
ancak bu sat&#305;rlar birbirine birle&#351;ik sat&#305;rlar

mesala 15. sat&#305;r da ko&#351;ul ger&#231;ekl&#351;eiyorsa
A,(BCD),(EF) s&#252;tunlar&#305;n&#305;n 15. sat&#305;rlar&#305; siyah dolgu beyaz yaz&#305; oluyor tabi s&#252;t = 6 olursa G,(HIJ),(KL) bu hale geliyor
A15:F15 aral&#305;&#287;&#305;n&#305; boya demenin yolu Cells i&#231;in nedir yani
s2.Select: Cells(c + 10, 1 + sut).Select
s2.Select: Cells(c + 10, 2 + sut).Select
s2.Select: Cells(c + 10, 5 + sut).Select

bunlar&#305; bir kerede se&#231; komutu nas&#305;l olmal&#305;
 
mesala 15. satır da koşul gerçeklşeiyorsa
A,(BCD),(EF) sütunlarının 15. satırları siyah dolgu beyaz yazı oluyor tabi süt = 6 olursa G,(HIJ),(KL) bu hale geliyor
A15:F15 aralığını boya demenin yolu Cells için nedir yani
s2.Select: Cells(c + 10, 1 + sut).Select
s2.Select: Cells(c + 10, 2 + sut).Select
s2.Select: Cells(c + 10, 5 + sut).Select

bunları bir kerede seç komutu nasıl olmalı

Şöyle ki :

Kod:
With s2.Range("A" & satir & ":F" & satir)
     With .Font
          .Bold = True
          .ColorIndex = 2
     End With
     .Interior.ColorIndex = 1
End With

NOT : "satir" değişkeninin değerinin önceden bulunduğu varsayilmiştır
 
say&#305;n fpc kast&#305;m &#351;u bu bi&#231;imlendirmeyi yapmak i&#231;in 12 sat&#305;rr harc&#305;yoruz;
ancak bu sat&#305;rlar birbirine birle&#351;ik sat&#305;rlar

mesala 15. sat&#305;r da ko&#351;ul ger&#231;ekl&#351;eiyorsa
A,(BCD),(EF) s&#252;tunlar&#305;n&#305;n 15. sat&#305;rlar&#305; siyah dolgu beyaz yaz&#305; oluyor tabi s&#252;t = 6 olursa G,(HIJ),(KL) bu hale geliyor
A15:F15 aral&#305;&#287;&#305;n&#305; boya demenin yolu Cells i&#231;in nedir yani
s2.Select: Cells(c + 10, 1 + sut).Select
s2.Select: Cells(c + 10, 2 + sut).Select
s2.Select: Cells(c + 10, 5 + sut).Select

bunlar&#305; bir kerede se&#231; komutu nas&#305;l olmal&#305;

&#350;&#246;yle ki :

Kod:
With s2.Range("A" & satir & ":F" & satir)
     With .Font
          .Bold = True
          .ColorIndex = 2
     End With
     .Interior.ColorIndex = 1
End With

NOT : "satir" de&#287;i&#351;keninin de&#287;erinin &#246;nceden bulundu&#287;u varsayilmi&#351;t&#305;r

sat&#305;r de&#287;i&#351;kenimiz c+10 ve &#246;nceden bulunmu&#351; halde......
sorun s&#252;tunda &#231;&#305;k&#305;yor bu durumda s&#252;tun de&#287;i&#351;kenimizde &#246;nceden bulunmu&#351; durumda 1 + sut (ancak no olarak) (sut=0 ise Harf Olarak A, sut = 6 ise harf olarak g) bu de&#287;eri nas&#305;l tesbit edece&#287;iz



Kod:
        s2.Cells((c + 10, 1 + sut ):(c + 10, 5 + sut) ).select
        Selection.Font.ColorIndex = 2
        Selection.Interior.ColorIndex = 1
        Selection.Font.Bold = True ''se&#231;ili h&#252;creyi siyah dolgu,beyaz kal&#305;n yaz


gibi bir&#351;ey istiyorum ama cells ile aral&#305;k tan&#305;mlanabiliyormu onu bilmiyorum...
 
A&#351;a&#287;&#305;daki kodu kendinize uyarlamaya &#231;al&#305;&#351;&#305;n&#305;z l&#252;tfen.

Kod:
Satir = 15 [COLOR=green]'sizde bu de&#287;i&#351;ken c+10 sanirim[/COLOR]
Sutun1 = 1 [COLOR=green]'ilk s&#252;tunun s&#305;ra numaras&#305;:Bu &#246;rnek i&#231;in A s&#252;tunu[/COLOR]
Sutun2 = 6[COLOR=green] 'son s&#252;tunun sira numaras&#305;, Bu &#214;rnek i&#231;in F s&#252;tunu[/COLOR]
[COLOR=green]'-------------------------------------[/COLOR]
[COLOR=green]'Siz ko&#351;ula g&#246;re 1 ve 6 olan s&#252;tun de&#287;erlerini[/COLOR]
[COLOR=green]'7 ve 12 olarak de&#287;i&#351;tirtirseniz[/COLOR]
[COLOR=green]'Bu sefer G ve L aras&#305;ndaki, ilgili satir bi&#231;imlenir[/COLOR]
[COLOR=green]'-------------------------------------[/COLOR]
With s2.Range(s2.Cells(Satir, Sutun1), s2.Cells(Satir, Sutun2))
     With .Font
          .Bold = True
          .ColorIndex = 2
     End With
     .Interior.ColorIndex = 1
End With
 
Son düzenleme:
A&#351;a&#287;&#305;daki kodu kendinize uyarlamaya &#231;al&#305;&#351;&#305;n&#305;z l&#252;tfen.

Kod:
Satir = 15 [COLOR=green]'sizde bu de&#287;i&#351;ken c+10 sanirim
[/COLOR]Sutun1 = 1 [COLOR=green]'ilk s&#252;tunun s&#305;ra numaras&#305;:Bu &#246;rnek i&#231;in A s&#252;tunu
[/COLOR]Sutun2 = 6[COLOR=green] 'son s&#252;tunun sira numaras&#305;, Bu &#214;rnek i&#231;in F s&#252;tunu
[/COLOR][COLOR=green]'-------------------------------------
'Siz ko&#351;ula g&#246;re 1 ve 6 olan s&#252;tun de&#287;erlerini
'7 ve 12 olarak de&#287;i&#351;tirtirseniz
'Bu sefer G ve L aras&#305;ndaki, ilgili satir bi&#231;imlenir
'-------------------------------------
[/COLOR]With s2.Range(s2.Cells(Sutun1, Satir), s2.Cells(Sutun2, Satir))
     With .Font
          .Bold = True
          .ColorIndex = 2
     End With
     .Interior.ColorIndex = 1
End With
''''''''''''''''''''''''''''''''''

s2.Cells((c + 10, 1 + sut ):(c + 10, 5 + sut) ).select

Kod:
Satir = c+10 sanirim
Sutun1 = 1 + sut 'ilk s&#252;tunun s&#305;ra numaras&#305;:Bu &#246;rnek i&#231;in A s&#252;tunu/sut=6 ise g
Sutun2 = 5 + sut [COLOR=red] 'son s&#252;tunun sira numaras&#305;, Bu &#214;rnek i&#231;in F s&#252;tunu 5+sut yaparsam e s&#252;tununnu bulrum ama e ve f birle&#351;tirilmi&#351; h&#252;cre 5 + sut + 1 mi kullanmal&#305;y&#305;m[/COLOR]

[COLOR=green]'-------------------------------------
'Siz ko&#351;ula g&#246;re 1 ve 6 olan s&#252;tun de&#287;erlerini
'7 ve 12 olarak de&#287;i&#351;tirtirseniz
'Bu sefer G ve L aras&#305;ndaki, ilgili satir bi&#231;imlenir
'-------------------------------------
[/COLOR]
With s2.Range(s2.Cells(1+sut, c+10), s2.Cells(5+sut, c+10))
yada
[COLOR=RED]With s2.Range(s2.Cells(1+sut, c+10), s2.Cells(5+sut+1, c+10))[/COLOR]
'sut = 0 iken 5+0= 5 ise e g&#252;cresinde de&#287;er yaz&#305;l&#305;yor
'ancak erim tan&#305;mlarken son h&#252;cre f olmas&#305; laz&#305;m ancak e ve f birle&#351;tirilmi&#351; h&#252;cre do&#287;ru kullan&#305;m
'hangisidir

     With .Font
          .Bold = True
          .ColorIndex = 2
     End With
     .Interior.ColorIndex = 1
End With

&#351;eklinde olmal&#305; herhalde ama hangisi deneyemedim &#231;&#252;nk&#252; usb diski i&#351;yerinde unutmu&#351;um :(
 
Sn.hsayar

Kusura bakmay&#305;n. 6 Nolu mesajda; Cells tan&#305;mlar&#305;ndaki, satir ve s&#252;tun referanslar&#305;nda syntax hatas&#305; yapm&#305;&#351;&#305;m. &#350;imdi farkettim ve d&#252;zelttim.

L&#252;tfen 6 Nolu mesaj&#305; yeniden inceleyiniz.
 
Kod:
....
...
...
    '12+V>>>>>>>>>>
    ElseIf s1.Cells(g, 1) = "12" And (s1.Cells(g, 2) = "V" Or s1.Cells(g, 2) = "v") Then
    c = c + 1
        'ikinci s&#252;tun kontrol&#252;
        If c = 35 Then
        sut = 6: c = 1
        End If
        'ev stok Kay&#305;t say&#305;s&#305; kontrol&#252;
        If WorksheetFunction.CountA(s2.[e11:e44,k11:k44]) = 68 Then
        MsgBox "Tablo doldu&#287;u i&#231;in kay&#305;t yap&#305;lamad&#305;.", , "UYARI": Exit Sub
        End If
    '12 lik stok &#231;&#305;k&#305;&#351; yazma i&#351;lemi
    s2.Cells(c + 10, 1 + sut) = s1.Cells(g, 5)
        [color=red]s2.Select: Cells(c + 10, 1 + sut).Select
        Selection.Font.ColorIndex = 2
        Selection.Interior.ColorIndex = 1
        Selection.Font.Bold = True ''se&#231;ili h&#252;creyi siyah dolgu,beyaz kal&#305;n yaz[/color]
    s2.Cells(c + 10, 2 + sut) = UCase(s1.Cells(g, 4))
        [color=red]s2.Select: Cells(c + 10, 2 + sut).Select
        Selection.Font.ColorIndex = 2
        Selection.Interior.ColorIndex = 1
        Selection.Font.Bold = True ''se&#231;ili h&#252;creyi siyah dolgu,beyaz kal&#305;n yaz [/color]
    s2.Cells(c + 10, 5 + sut) = s1.Cells(g, 7)
        [color=red]s2.Select: Cells(c + 10, 5 + sut).Select
        Selection.Font.ColorIndex = 2
        Selection.Interior.ColorIndex = 1
        Selection.Font.Bold = True ''se&#231;ili h&#252;creyi siyah dolgu,beyaz kal&#305;n yaz [/color]
    '<<<<<<<<<<<<<<<<<12+V
    End If
....
....
....

Say&#305;n fpc hocama te&#351;ekk&#252;r ederim
Kodalr&#305;n yeni hali;

Kod:
    '12+V>>>>>>>>>>
    ElseIf s1.Cells(g, 1) = "12" And (s1.Cells(g, 2) = "V" Or s1.Cells(g, 2) = "v") Then
    c = c + 1
        'ikinci s&#252;tun kontrol&#252;
        If c = 35 Then
        sut = 6: c = 1
        End If
        'ev stok Kay&#305;t say&#305;s&#305; kontrol&#252;
        If WorksheetFunction.CountA(s2.[e11:e44,k11:k44]) = 68 Then
        MsgBox "Tablo doldu&#287;u i&#231;in kay&#305;t yap&#305;lamad&#305;.", , "UYARI": Exit Sub
        End If
    '12 lik stok &#231;&#305;k&#305;&#351; yazma i&#351;lemi
    s2.Cells(c + 10, 1 + sut) = s1.Cells(g, 5)
    s2.Cells(c + 10, 2 + sut) = UCase(s1.Cells(g, 4))
    s2.Cells(c + 10, 5 + sut) = s1.Cells(g, 7)
        '>>>>>>>>>>>>>>>>>>>>>>>bi&#231;imlendir
[color=red]        With s2.Range(s2.Cells(c + 10, 1 + sut), s2.Cells(c + 10, 5 + sut + 1))
          With .Font: .Bold = True: .ColorIndex = 2: End With: .Interior.ColorIndex = 1
        End With[/color]
        '<<<<<<<<<<<<<<<<<<<<<<<bi&#231;imlendir
'<<<<<<<<<<<<<<<<<12+V
    End If
 
Geri
Üst