Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1192to1196
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Code optimieren

Code optimieren
peter
Hallo, ein frohes neues Jahr wünsche ich Euch.
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 das
nicht hin. Kann mir evtl einer helfen. Danke im vorraus.
Grüße
Peter

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Code optimieren
08.01.2011 10:19:21
ransi
HAllo
Ich habe deine DAtei nicht, darum mal ungetestet:
Option Explicit

Private Sub ListBox1_Click()
    Dim L As Long
    For L = 1 To 10 '?
        For i = 7 To 13
            If Cells(L, i).Value > 0 Then
                Me.Controls("TextBox" & i + 3).BackColor = RGB(0, 255, 0)
            Else
                Me.Controls("TextBox" & i + 3).BackColor = RGB(255, 0, 0)
            End If
        Next i
    Next L
End Sub



ransi
Anzeige
AW: Code optimieren
08.01.2011 10:46:46
Peter
Hallo Ransi
vielen Dank für die super schnelle Hilfe.
Es funktioniert.
Danke
Grüße Peter
AW: Code optimieren
08.01.2011 10:35:41
Gerd
Hallo Peter,
in Userform, in Tabelle aus ActiveX / Formularleiste ?
Private Sub ListBox1_Click()
Dim lngZeile As Long, lngSpalte As Long
lngZeile = 3
For lngSpalte = 7 To 13
Controls("TextBox" & lngSpalte + 3).BackColor = IIf(Cells(lngZeile, lngSpalte).Value > 0, RGB(0, _
255, 0), Rng(255, 0, 0)) '?
OLEObjects("TextBox" & lngSpalte + 3).Object.BackColor = IIf(Cells(lngZeile, lngSpalte).Value >  _
0, RGB(0, 255, 0), Rng(255, 0, 0)) '?
OLEFormat("TextBox" & lngSpalte + 3).Object.BackColor = IIf(Cells(lngZeile, lngSpalte).Value >  _
0, RGB(0, 255, 0), Rng(255, 0, 0)) '?
Next
End Sub
Gruß Gerd
Anzeige
AW: Code optimieren
08.01.2011 10:59:50
Peter
Hallo Gerd,
Code ist in Userform.
Danke für die schnelle Antwort werde das jetzt auch mal aus probieren.
Grüße
Peter

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige