AW: Bedingte Formatierung als VBA
08.11.2019 06:26:45
Klaus
Hallo Laui,
ich habe einmal die bedingte Formatierung durch den Makrorekorder gejagt und dann die Zeilennummer variabel gestaltet. Hier das Ergebnis:
Sub MakroMacheFormatierung()
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=A" & ActiveCell.Row & "38"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B" & ActiveCell.Row & "= _
""Nicht abgeschlossen"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
End Sub
Das Makro kannst du entweder manuell aufrufen um die selektierte Zelle bedingt zu formatieren, oder du kannst es an ein passendes Change-Ereignis hängen. Da ich nicht weiß wie genau neue Zeilen in deine Tabelle kommen, kann ich nur raten. Das hier könnte, zum Beispiel, funktionieren:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lRow As Long
Const myCol As Long = 1 'Spalte A
If Target.Column = myCol Then 'nur Spalte A
lRow = Cells(Rows.Count, myCol).End(xlUp).Row
If Target.Row = lRow Then
Application.EnableEvents = False
Selection.Offset(-1, 0).Select
MakroMacheFormatierung
Application.EnableEvents = True
End If
End If
End Sub
LG,
Klaus M