Option Explicit
Option Compare Text
'(c)1999 Andreas Kirschbaum
Const TrennZ = "-+/*^()"
Const ZahlZ = "-.,0123456789"
Const HochZ = "0123"
Const Hoch2Z = "º¹²³"
Function FORMELTEXT(Bereich, Aktuell As String) As String
Dim Art As Integer, i As Integer, j As Integer, k As Integer, n As Integer
Dim BezAnf As Integer
Dim tI As String, tA As String, c As String * 1, buf As String * 256, tF As String
On Error Resume Next
tI = Bereich.FormulaLocal
If Left(tI, 1) = "=" Then
tA = ""
Art = 0 ' 0: Operand erwartet
n = Len(tI)
For i = 2 To n + 1
If i > n Then
c = ""
k = 1
Else
c = Mid(tI, i, 1)
k = InStr(TrennZ, c)
End If
If k = 0 Then
k = InStr(ZahlZ, c)
If k = 0 Then
If Art = 0 Then
Art = 2 ' 2: Bezug oder Funktion
BezAnf = i
End If
Else
If Art 0 And (i + 1 = n Or InStr(TrennZ, Mid(tI, i + 2, 1)) > 0) Then
c = Mid(Hoch2Z, j, 1)
i = i + 1
End If
End Select
tA = tA & c
Art = 0 ' 0: Operand erwartet
End If
Next
n = Len(tA)
buf = tA
FORMELTEXT = Left(tA, n)
Else
FORMELTEXT = ""
End If
End Function
Allerdings aktualisiert sich diese Funktion nicht automatisch, wenn man einen Wert ändert und ich finde den Fehler einfach nicht.
Ich hatte es auch schon mit einem Application.Volatile am Funktionsanfang versucht, was grundsätzlich geht. Allerdings habe ich dann das Problem, wenn ich die Funktion in einem Arbeitsblatt A aufrufe, werden die Werte in Arbeitsblatt B wieder gelöscht und es stehen keine Zahlen mehr da. In obigem Beispiel würde dann nur noch "*" erscheinen.
Wäre nett, wenn mir jemand sagen könnte, was ich da ändern muss. Gefunden habe ich leider außer diesem Volatile keine weiteren Lösungsansätze, wobei dieses eben auch nicht wirklich optimal ist.