Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.04.2024 18:33:31
28.04.2024 18:25:12
28.04.2024 14:18:05
Anzeige
Archiv - Navigation
1936to1940
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

Interior.ColorIndex vs. Conditional Formatting

Interior.ColorIndex vs. Conditional Formatting
02.08.2023 12:51:54
Tor
Hallo zusammen,

Ich faerbe mit folgendem Code bei bestimmten Eingaben die Zelle ein und passe die Schriftfarbe an.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


Dim rngRange As Range, rngCell As Range
Set rngRange = Range("F10:AJ159")

For Each rngCell In Range(Target.Address)
If Not Intersect(rngCell, rngRange) Is Nothing Then
Select Case UCase(rngCell.Value)
Case "LL"
ActiveSheet.Unprotect
rngCell.Interior.ColorIndex = 4 ' green
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case "LL½"
ActiveSheet.Unprotect
rngCell.Interior.ColorIndex = 4 ' green
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case "LOP"
ActiveSheet.Unprotect
rngCell.Interior.ColorIndex = 16 ' grey
rngCell.Font.ColorIndex = 2 ' white
ActiveSheet.Protect
Case "HLOP"
ActiveSheet.Unprotect
rngCell.Interior.ColorIndex = 16 ' grey
rngCell.Font.ColorIndex = 2 ' white
ActiveSheet.Protect
Case "SL"
ActiveSheet.Unprotect
rngCell.Interior.ColorIndex = 3 ' red
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case "SL½"
ActiveSheet.Unprotect
rngCell.Interior.ColorIndex = 3 ' red
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case Else
ActiveSheet.Unprotect
rngCell.Interior.ColorIndex = 2 ' none
ActiveSheet.Protect
End Select
End If
Next rngCell

Set rngRange = Nothing

End Sub

Das funktioniert auch super. Allerdings nicht, wenn per conditional formatting Zellen schon vorher eingefaerbt waren. Wie kann ich das Einfaerben vom conditional formatting ueberschreiben?
Vielen Dank fuer Eure Hilfe

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

Betreff
Datum
Anwender
Anzeige
AW: Interior.ColorIndex vs. Conditional Formatting
02.08.2023 12:57:05
Rudi Maintaire
Hallo,
Wie kann ich das Einfaerben vom conditional formatting ueberschreiben?
gar nicht. Du musst sie löschen.

Range(Target.Address)
ist Quatsch. Target reicht vollkommen.
For Each rngCell In Target

Gruß
Rudi
AW: Interior.ColorIndex vs. Conditional Formatting
03.08.2023 13:04:44
Tor
Hallo Rudi,

Danke auch dir fuer deine Antwort. Also ich hab mal den Code geaendert und das Loeschen der bed. Formatierung funktioniert auch wunderbar und die Zelle wird neu eingefaerbt.
Jetzt moechte ich aber, wenn der Inhalt der Zelle wieder geloescht wird, den alten Zustand wieder herstellen. Dazu dachte ich mir, die darunter liegende Zelle zu kopieren im Case Else Zweig, da die ja die urspruengliche bed. Formatierung hat, und mit .PasteSpecial xlPasteFormats in der Target Zelle wieder einzufuegen. Leider klappt das nicht so wie gedacht. Excel rechnet ein paar Sekunden und stuerzt dann einfach ab. Wo liegt hier mein Fehler? Nochmal der Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


Dim rngRange As Range, rngCell As Range
Set rngRange = Range("F10:AJ159")

For Each rngCell In Range(Target)
If Not Intersect(rngCell, rngRange) Is Nothing Then
Select Case UCase(rngCell.Value)
Case "LL"
ActiveSheet.Unprotect
rngCell.FormatConditions(1).Delete
rngCell.Interior.ColorIndex = 4 ' green
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case "LL½"
ActiveSheet.Unprotect
rngCell.FormatConditions(1).Delete
rngCell.Interior.ColorIndex = 4 ' green
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case "LOP"
ActiveSheet.Unprotect
rngCell.FormatConditions(1).Delete
rngCell.Interior.ColorIndex = 16 ' grey
rngCell.Font.ColorIndex = 2 ' white
ActiveSheet.Protect
Case "HLOP"
ActiveSheet.Unprotect
rngCell.FormatConditions(1).Delete
rngCell.Interior.ColorIndex = 16 ' grey
rngCell.Font.ColorIndex = 2 ' white
ActiveSheet.Protect
Case "SL"
ActiveSheet.Unprotect
rngCell.FormatConditions(1).Delete
rngCell.Interior.ColorIndex = 3 ' red
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case "SL½"
ActiveSheet.Unprotect
rngCell.FormatConditions(1).Delete
rngCell.Interior.ColorIndex = 3 ' red
rngCell.Font.ColorIndex = 1 ' black
ActiveSheet.Protect
Case Else
ActiveSheet.Unprotect
rngCell.Offset(1, 0).Copy: rngCell.PasteSpecial xlPasteFormats
ActiveSheet.Protect
End Select
End If
Next rngCell

Set rngRange = Nothing

End Sub

Nochmals Danke fuer eure Hilfe
Tor
Anzeige
AW: Interior.ColorIndex vs. Conditional Formatting
02.08.2023 12:55:31
daniel
Hi
gar nicht.
die Bedingte Formatierung hat Priorität.
du kannst höchsten die Bedingten Formate für diese Zelle löschen.
Die Farbe der Bedingten Formatierung ändern wird aufwendig.
Gruß Daniel
AW: Interior.ColorIndex vs. Conditional Formatting
02.08.2023 13:04:28
Tor
Hallo Daniel,

Danke fuer deine schnelle Antwort.
OK. Dann muss ich mal schauen.

196 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige