• DİKKAT

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

If then else kullanımı

  • Konbuyu başlatan Konbuyu başlatan seddur
  • Başlangıç tarihi Başlangıç tarihi
Katılım
12 Nisan 2012
Mesajlar
533
Excel Vers. ve Dili
Microsoft office professional plus 2019
Merhaba."A1" hücresi boşsa commandbutton1 arkaplan rengi yeşil doluysa kırmızı,yine aynı şekilde "A2" hücresi boşsa commandbutton2 arkaplan rengi yeşil,doluysa kırmızı olacak şekilde kod yazmak istiyorum.Toplam 12 adet commandbutton var.Aşağıdaki kod çalışmadı.Yardımcı olursanız sevinirim.

Private Sub UserForm_Activate()
Dim s1 As Worksheet
Set s1 = Sheets("Anasayfa")
If s1.Cells(1, 1) <> "" Then
CommandButton1.BackColor = RGB(139, 0, 0)
Else
CommandButton1.BackColor = RGB(0, 153, 0)
If s1.Cells(2, 1) <> "" Then
CommandButton2.BackColor = RGB(139, 0, 0)
Else
CommandButton2.BackColor = RGB(0, 153, 0)
End If: End If:
 
Merhaba,

Deneyiniz.
Kod:
    Dim i As Byte, s1 As Worksheet
    
    Set s1 = Sheets("Anasayfa")
    
    For i = 1 To 12
        If Cells(i, "A") <> "" Then
            Controls("CommandButton" & i).BackColor = RGB(139, 0, 0)
        Else
            Controls("CommandButton" & i).BackColor = RGB(0, 153, 0)
        End If
    Next i
 
Geri
Üst