AW: bedingte Formatierung ersetzen - VBA
19.03.2009 12:41:03
Daniel
Hi
das liegt nicht an den bedingten Formaten, sondern daran, daß du dich in der Struktur der WITH-Klammern verheddert hast. Wenn man die richtig stellt, funktionierts einwandfrei.
Sub AAAABedingte_Formatierung()
With ActiveWorkbook.Sheets("tabelle1")
With .Cells(1, 1).SpecialCells(xlCellTypeAllFormatConditions)
.Select
With .FormatConditions
.Delete
.Add Type:=xlExpression, Formula1:="=A5>1,5"
End With
.FormatConditions(1).Interior.ColorIndex = 34
With .FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .FormatConditions(1).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .FormatConditions(1).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .FormatConditions(1).Interior
.ColorIndex = 22
.Pattern = xlSemiGray75
End With
End With
End With
End Sub
(den Sheetnamen habe ich zum Testen angepasst)
allerdings würde ich empfehlen, beim Formulieren der Formel für die Bedingtte Formatierung die Z1S1-Schreibweise zu verwenden und nicht die A1-Schreibweise.
die A1-Schreibweise ist gefährlich, da es hier auch darauf ankommt, welche Zelle gerade aktiv, daher ist hier die Z1S1-Schreibweise wesentlich sicherer.
du kannst die Z1S1-Schreibweise genauso verwenden (in Deutsch), wie die A1-Schreibweise, ohne irgendwelche andern Angaben machen zu müssen. bei der Bedingent Formatierung ist es Excel egal.
Gruß, Daniel