Jetzt Problem mit mehreren BedFor
22.09.2016 11:51:53
MB12
Hi,
nachdem ich zwei bed.Formatierungen (Nr. 2+3) für den gleichen Bereich erstellt habe, geschieht folgendes:
Sub BedFor() ' grün wenn Summenzelle = 0
Application.ScreenUpdating = False
Cells.FormatConditions.Delete
If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData
ActiveSheet.Range("$A$5:$K$1100").AutoFilter Field:=1, Criteria1:=""
' (1)Summenzelle grün wenn = 0
Range("L7").CurrentRegion.SpecialCells(xlCellTypeVisible).FormatConditions.Add _
Type:=xlCellValue, Operator:=xlEqual, Formula1:=0
Range("L7").CurrentRegion.FormatConditions(1).Interior.Color = 13434777
Range("L7").CurrentRegion.FormatConditions(1).StopIfTrue = False
' (2)Tageszellen rot Vergangenheit (Datum in F1)
Range("L2:KO2").SpecialCells(xlCellTypeVisible).FormatConditions.Add _
Type:=xlCellValue, Operator:=xlLess, Formula1:="=$F$1"
Range("L2:KO2").FormatConditions(1).Interior.Color = 13551615
Range("L2:KO2").FormatConditions(1).StopIfTrue = False
'**********korrekt; wird ab L2 incl. 21.09. rot**************
' (3)Tageszelle grün heute (Datum in F1)
Range("L2:KO2").SpecialCells(xlCellTypeVisible).FormatConditions.Add _
Type:=xlCellValue, Operator:=xlEqual, Formula1:="=$F$1"
Range("L2:KO2").FormatConditions(1).Interior.Color = 13561798
Range("L2:KO2").FormatConditions(1).StopIfTrue = False
'**********falsch; jetzt sind alle Zellen ab L2 incl. 22.09. (heute) grün*************** _
ActiveSheet.ShowAllData
Columns("I:K").FormatConditions.Delete
Application.ScreenUpdating = True
Range("A1").Select
End Sub
Es ist mir klar, dass es mit der Priority zu tun haben muss, denn wenn ich 2+3 umstelle, wird das Tagesdatum rot - ächz.
Mit dem Makrorekorder funktioniert es, ist aber alles andere als schön:
Sub Makro6()
' Makro6 Makro
Range("L2:BI2").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="=$F$1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=$F$1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16752384
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13561798
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("H2").Select
End Sub
Eine Idee wäre hochwillkommen, danke schön
Gruß, Margarete