Code optimieren
peter
Ich möchte diverse Zellen abfragen und dann jenach Inhalt eine Textbox farblich darstellen.
Dazu habe ich das so gemacht.
Private Sub ListBox1_Click()
If Cells(lng, 7).Value > 0 Then
TextBox10.BackColor = RGB(0, 255, 0)
Else
TextBox10.BackColor = RGB(255, 0, 0)
End If
If Cells(lng, 8).Value > 0 Then
TextBox11.BackColor = RGB(0, 255, 0)
Else
TextBox11.BackColor = RGB(255, 0, 0)
End If
If Cells(lng, 9).Value > 0 Then
TextBox12.BackColor = RGB(0, 255, 0)
Else
TextBox12.BackColor = RGB(255, 0, 0)
End If
If Cells(lng, 10).Value > 0 Then
TextBox13.BackColor = RGB(0, 255, 0)
Else
TextBox13.BackColor = RGB(255, 0, 0)
End If
If Cells(lng, 11).Value > 0 Then
TextBox14.BackColor = RGB(0, 255, 0)
Else
TextBox14.BackColor = RGB(255, 0, 0)
End If
If Cells(lng, 12).Value > 0 Then
TextBox15.BackColor = RGB(0, 255, 0)
Else
TextBox15.BackColor = RGB(255, 0, 0)
End If
If Cells(lng, 13).Value > 0 Then
TextBox16.BackColor = RGB(0, 255, 0)
Else
TextBox16.BackColor = RGB(255, 0, 0)
End If
End With
End Sub
Ich habe jetzt versucht dies zu optimieren weil das längst noch nicht alle Zellen sind aber ich bekomme dasnicht hin. Kann mir evtl einer helfen. Danke im vorraus.
Grüße
Peter