Saya tahu sedikit tentang pemrograman dan jawaban saya tidak elegan. Sebagai insinyur masa depan saya membutuhkan fungsi di Excel yang bisa menampilkan kepada saya formula. Masalah yang saya temukan dalam solusi Indrek adalah fungsinya mengembalikan kepada saya rumus seperti ini: "C9 * C9 * pi ()" dan saya ingin nama sel di tampilan rumus (C9) diubah menjadi nilai-nilai sel-sel itu; dan itu akan secara otomatis berubah setiap kali angka-angka itu diubah dalam sel C9 asli.
Semacam kode saya berfungsi dengan formula yang sangat dasar. Saya tidak pernah menemukan sesuatu seperti ini di tempat lain, Mungkin membantu seseorang atau tidak. Seseorang mungkin dapat meningkatkan ini ke tingkat yang layak. Seperti yang saya katakan, ini bekerja untuk saya dan saya adalah orang yang praktis dengan sedikit keterampilan dalam pemrograman.
Fungsi pertama bukan milikku sama sekali. Itu diambil dari:
/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