AW: Bedignte Formatierung VBA
18.11.2016 13:40:48
fcs
Hallo Max,
per Makro kann man es wie folgt umsetzen.
Für die Formel: System-EInstellung Deutsch, Excel: Deutsch
Bei anderen Sprachen, Einstellungen muss in der Formel ggf. das "UND" und das ";" geändert werden.
LG
Franz
Sub prcBedingtFormatieren()
' prcBedingtFormatieren Makro
' Spalten B:AD bedingt formatieren, abhängig von Wert in Spalte AG
Dim rngBereich As Range, rngWert As Range
Dim strFormelBereich As String, strFormelWert As String, strFormel As String
With ActiveSheet
Set rngBereich = Range(.Cells(3, 2), .Cells(.Rows.Count, 30))
strFormelBereich = rngBereich.Range("A1").Address(rowabsolute:=False, _
columnabsolute:=False, ReferenceStyle:=xlA1)
'Meine Range für das Nominal ist:
Set rngWert = Range(.Cells(3, 33), .Cells(.Rows.Count, 33))
strFormelWert = rngWert.Range("A1").Address(rowabsolute:=False, _
columnabsolute:=True, ReferenceStyle:=xlA1)
End With
rngBereich.Select
With rngBereich
.FormatConditions.Delete
strFormel = "=UND(" & strFormelBereich & """"")"
.FormatConditions.Add Type:=xlExpression, Formula1:=strFormel
.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(red:=255, green:=0, blue:=0) 'Rot
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
strFormel = "=UND(" & strFormelBereich & """"")"
.FormatConditions.Add Type:=xlExpression, Formula1:=strFormel
.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(red:=0, green:=255, blue:=255) 'hellblau
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
strFormel = "=UND(" & strFormelBereich & """"")"
.FormatConditions.Add Type:=xlExpression, Formula1:=strFormel
.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(red:=255, green:=255, blue:=0) 'gelb
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
strFormel = "=UND(" & strFormelBereich & """"")"
.FormatConditions.Add Type:=xlExpression, Formula1:=strFormel
.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(red:=128, green:=255, blue:=128) 'hell grün
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
.Range("A1").Select
End With
End Sub