Solved: Is it possible to enter a UDF into a cell and replace it w a native Excel formula?
Consider this simple piece of "concept" code that stops executing at the line of code that starts w ".Formula" and returns ?NAME ...
[VBA]
Function TestConcept(sVars As String) As String
Dim iSum As Integer
With Range("A1")
MsgBox .Formula ' shows UDF
.Formula = "=SUM(B1:B3)" ' I want to overwrite UDF w this
MsgBox .Formula ' show updated formula
TestConcept = .Formula ' just there to complete UDF
End With
End Function
[/VBA]
I'm trying to construct a UDF that replaces the originally entered UDF w a standard Excel formula, all in a single step.
So here's the macro-level explanation...
- Enter "=TestConcept("BuilderParameters") into a given cell
- The UDF executes, and in the proposed finished code, it finds all of the cell names in a given range that match a certain criteria
- Once a match is found, construct a new formula as it iterates through the given range
- On completion, update this cell's .Formula w the "new" Formula.
- In the end, I would replace a slow-executing UDF w a native code Excel calculation.
What am I doing wrong, or better yet, is it even possible to construct a native Excel formula "builder" via a "one shot" (e.g., as soon as it executes, it replaces itself) UDF?
Thank you for considering this question.