Gruppe
Feature
Bereich
Bedingt
Thema
Bedingte Formatierung auslesen
Problem
Wie kann ich die Bedingungen der bedingten Formatierung und die Auswirkung auf die formatierte Zelle auslesen?
Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.
StandardModule: basMain
Sub FormCond()
Dim iFormula As Integer, iColorA As Integer
Dim iColorB As Integer
With Range("A1").FormatConditions(1)
iFormula = .Formula1
iColorA = .Font.ColorIndex
iColorB = Range("A1").Font.ColorIndex
If iColorB = -4105 Then iColorB = "'Automatisch'"
If Range("A1").Value = iFormula Then
MsgBox "Bedingung '" & iFormula & "' ist erfüllt" _
& vbLf & "Die aktuelle Schriftfarbe ist " & iColorA
Else
MsgBox "Bedingung '" & iFormula & "' ist nicht erfüllt" _
& vbLf & "Die aktuelle Schriftfarbe ist " & iColorB
End If
End With
End Sub