Deshalb möchte ich das Problem hier noch mal vereinfacht anfragen:
Ich habe eine Routine FARBE erstellt
In dieser Routine wird ein String erstellt und über MsgBox und debug.print ausgegeben
die Ausgabe lautet:
"= UND(U1 = ""MFM"" ; J1 ""G"")"
später in der Routine soll dieser Szring als Formel für bedingte Formatierung verwendet werden, und das klappt nicht.
Wenn ich aber den Ausdruck aus debug.print dort einsetze, dann klappt es problemlos
das verstehe ich nicht! Kann mir jemand da helfen?
Das ist meine Routine:
Sub FARBE()
Dim i As Integer
Dim STUECKE(1, 2) As String
STUECKE(1, 1) = "MFM"
STUECKE(1, 2) = "J"
i = 1
FORMEL = """= UND(U1 = " & """""" & STUECKE(i, 1) & """""" & " ; " & STUECKE(i, 2) & "1 _
""""" & "G" & """""" & ")" & """"
Debug.Print FORMEL
Range("G:G").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.FormatConditions.Delete
' Bedingung für grünen Zellhintergrund
With .FormatConditions.Add(Type:=xlExpression, Formula1:=FORMEL)
.Interior.ColorIndex = 43
End With
End With
End Sub