私はプログラミングについてはほとんど知りませんが、私の答えはエレガントではありません。将来のエンジニアとして、数式を表示できるExcelの関数が必要でした。Indrekソリューションで見つけた問題は、彼の関数が「C9 * C9 * pi()」のような式を私に返すことであり、式(C9)の表示でセルの名前をそれらの細胞; 元のC9セルでこれらの数値が変更されると、自動的に変更されます。
私のコードは非常に基本的な数式で動作します。私はどこにもこのようなものを見つけたことはありません、それは誰かを助けるかどうかにかかわらずかもしれません。誰かがこれをまともなレベルに改善できるかもしれません。私が言ったように、それは私のために働き、私はプログラミングのスキルがほとんどない実用的な男です。
最初の機能は私のものではありません。次から取得されました:
/programming/10951687/how-to-search-for-string-in-an-array
Function IsInArray(ar, item$) As Boolean
Dim delimiter$, list$
' Chr(7) is the ASCII 'Bell' Character.
' It was chosen for being unlikely to be found in a normal array.
delimiter = Chr(7)
' Create a list string containing all the items in the array separated by the delimiter.
list = delimiter & Join(ar, delimiter) & delimiter
IsInArray = InStr(list, delimiter & item & delimiter) > 0
End Function
Function GETFORMULA(cell)
Dim alfabeto As String
Dim alfabetos() As String
Dim formula As String
Dim celda As String
Dim cutter As String
Dim cutterarray() As String
'The formula is taken from the cell
formula = cell.formula
'And alphabet is declared to be compared with the formula
alfabeto = "A,B,C,D,E,F,G,H,I,J,K,L,M,O,P,Q,R,S,T,U,V,W,X,Y,Z"
'An array is declared with the elements of the alphabet string
alfabetos = Split(alfabeto, ",")
'Replacing common functions with a symbol, otherwise the code will crash
formula = Replace(formula, "LOG", "#")
formula = Replace(formula, "SQRT", "?")
formula = Replace(formula, "PI", "ñ")
'MsgBox (formula)
Debug.Print formula
'Symbols to identify where the name of a cell might end are declared
cutter = "*,/,+,-,^,(,)"
'An array is declared with the symbols from the string that has been just declared
cutterarray = Split(cutter, ",")
Dim nuevaformula As String
'For the i position in the lenght of the formula
Dim index As Integer
For i = 1 To Len(formula)
Debug.Print "Para i iterativo=", i
Debug.Print "Se tiene el digito", Mid(formula, i, 1)
'if the i element is not a letter, then add it to the chain of characters
If IsInArray(alfabetos, Mid(formula, i, 1)) = False Then
Debug.Print "Que es un numero"
nuevaformula = nuevaformula + Mid(formula, i, 1)
Debug.Print nuevaformula
'if the element is a letter, then it´s necessary to get the name of the cell, found all the numbers
'of the cell until a symbol to cut appears, like a: "*","/","+","-"
Else
Debug.Print "Encontramos una letra"
'Empezamos a buscar más números
'Numbers in the cell name are going to be find to isolate the cell number
For s = 2 To 7
celda = Mid(formula, i, s)
Debug.Print "Incrementamos una posición quedando", celda
If (i + s - 1 = Len(formula)) = False Then
'if a symbol to cut is not found in the last increment the last number hasn´t been reached
'and it´s necessary to keep loking for it
If IsInArray(cutterarray, Right(celda, 1)) = False Then
celda = Mid(formula, i, s)
Debug.Print "En el incremento no se encontró cutter. La i correcta es", i + s - 1
Else
'if it´s found the name of the cell is
celda = Mid(formula, i, s - 1)
Debug.Print "Se encontró un cutter la celda es", celda
'the search cycle has to be broken
Debug.Print s, i
i = i + s - 2
Debug.Print "Daremos salto a i=", i
Debug.Print celda
nuevaformula = nuevaformula + CStr(Range(celda).Value)
Exit For
End If
Else
Debug.Print "se alcanzó la máxima cantidad de iteraciones posibles"
celda = Mid(formula, i, s)
Debug.Print "La celda encontrada fue", celda
nuevaformula = nuevaformula + CStr(Range(celda).Value)
Debug.Print nuevaformula
nuevaformula = Replace(nuevaformula, "#", "LOG10")
nuevaformula = Replace(nuevaformula, "?", "raiz")
nuevaformula = Replace(nuevaformula, "ñ", "pi")
ISAAC = nuevaformula
Debug.Print (nuevaformula)
Exit Function
End If
'MsgBox (nuevaformula)
Next s
End If
Next i
nuevaformula = Replace(nuevaformula, "#", "LOG10")
nuevaformula = Replace(nuevaformula, "?", "raiz")
nuevaformula = Replace(nuevaformula, "ñ", "pi")
GETFORMULA = nuevaformula
Debug.Print (nuevaformula)
End Function