ich möchte gern eine bedingte Formatierung in ein Spalte automatisch hinterlegen.
Die Spalte "H" angefangen ab Zeile 4, bis die letzte belegte Spalte in Spalte "G" erreicht wird.
mfg walter mb
Sub BedingteFormatierung()
Dim rng As Range, L As Long
' ActiveSheet.UsedRange.Rows.Count gibt die letzte benutze Zeile unabhängig von
' den Spalten zurück
L = ActiveSheet.UsedRange.Rows.Count
Set rng = Range("G4:H" & L)
With rng
' evtl vorhandene Bed. Formatierung löschen
.FormatConditions.Delete
' Bedingte Formatierung setzen
' (hier: wenn Zellwert ungleich 2 dann Schrift Fett und Füllfarbe Hellgrün)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, Formula1:="2"
With .FormatConditions(1).Font
.Bold = True
.Italic = False
End With
.FormatConditions(1).Interior.ColorIndex = 35
End With
End Sub
Gruß
Set rng = Union(Range("J4:J" & L), Range("K4:K" & L))
Dim rng As Range, L As Long
' ActiveSheet.UsedRange.Rows.Count gibt die letzte benutze Zeile unabhängig von
' den Spalten zurück
L = Cells(Rows.Count, 8).End(xlUp).Row
Set rng = Range("J4:J" & L)
With rng
' evtl vorhandene Bed. Formatierung löschen
.FormatConditions.Delete
' Bedingte Formatierung setzen
' (hier: wenn Zellwert ungleich 0 dann Schrift Fett und Füllfarbe Hellgrün)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, Formula1:="0"
With .FormatConditions(1).Font
.Bold = True
.Italic = False
End With
.FormatConditions(1).Interior.ColorIndex = 35
End With
Private Sub CommandButton1_Click()
Dim rng As Range, L As Long
L = Cells(Rows.Count, 8).End(xlUp).Row 'das hatte ich neu
Set rng = Union(Range("J4:J" & L), Range("L4:L" & L), Range("N4:N" & L)) 'mehrere Bereiche
With rng
' evtl vorhandene Bed. Formatierung löschen
.FormatConditions.Delete
' Bedingte Formatierung setzen
' (hier: wenn Zellwert ungleich 0 dann Schrift Fett und Füllfarbe Hellgrün)
.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, Formula1:="0"
With .FormatConditions(1).Font
.Bold = True
.Italic = False
End With
.FormatConditions(1).Interior.ColorIndex = 35
End With
End Sub
Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden
Suche nach den besten AntwortenEntdecke unsere meistgeklickten Beiträge in der Google Suche
Top 100 Threads jetzt ansehen