hier noch 2 Varianten
28.05.2011 08:24:03
Matthias
Hallo
Hier mal noch 2 Varianten, alternativ zu Select Case (siehe Jens)
Die Beispiele beziehen sich auf den Zellbereich "A1:A15" des aktiven Blattes
Option Explicit
Sub stefan() 'bedingtes Format im Bereich löschen
Range("A1:A15").FormatConditions.Delete
End Sub
Sub bedForms() 'Variante 1 ( 'mit Union wären aber nur 30 Argumente möglich ! )
With Union(Range("A1"), Range("A3"), Range("A5"), Range("A7"), Range("A9"), Range("A11"), Range( _
"A13"), Range("A15"))
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="50"
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="50", Formula2:="79,99"
.FormatConditions(2).Interior.ColorIndex = 6
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="80"
.FormatConditions(3).Interior.ColorIndex = 43
End With
End Sub
Sub schleife() 'Variante 2
Dim x&
For x = 1 To 15 Step 2
With Range("A" & x)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="50"
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
Formula1:="50", Formula2:="79,99"
.FormatConditions(2).Interior.ColorIndex = 6
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="80"
.FormatConditions(3).Interior.ColorIndex = 43
End With
Next
End Sub
Zum Testen:
https://www.herber.de/bbs/user/75061.xls
Hinweis:
Anstatt die Zellen wieder bedingt zu formatieren, könntest Du Diese auch gleich mit VBA färben.