C
curiousgeorge408
I want to write a VB function (not a sub) that does something similar
to Solver (but nothing nearly as sophisticated or generalized) insofar
as it finds the "best" result by trial and error. The algorithm is
tailored to the purpose of the worksheet.
Ideally, the function would modify some cells in the active worksheet
(identified by name or passed as arguments) and let Excel automatic
calculation derive the result in a "target" cell, which depends on the
modified the cells directly or indirectly, just as if I were manually
modifying the cells manually. (Ideally, the "target" cell is the same
cell that contains the function call.)
This works as a macro (sub). But it appears that a UDF (function) is
not permitted to modify cells of either the active worksheet or even
another worksheet.
I just want to confirm that this cannot be done in a UDF. Or is there
some way that I can do it?
I know that I could duplicate all of the formula calculations within
the UDF. But I do not want to hardcode the formulas in VB. Instead,
I want the flexibility of changing the formulas in one place, namely
the worksheet.
I believe I could use Evaluate to execute each formula within the VB
function. I will work with that idea. But I am concerned that it
will be a lot slower than Excel.
Are there good alternatives that I have overlooked?
to Solver (but nothing nearly as sophisticated or generalized) insofar
as it finds the "best" result by trial and error. The algorithm is
tailored to the purpose of the worksheet.
Ideally, the function would modify some cells in the active worksheet
(identified by name or passed as arguments) and let Excel automatic
calculation derive the result in a "target" cell, which depends on the
modified the cells directly or indirectly, just as if I were manually
modifying the cells manually. (Ideally, the "target" cell is the same
cell that contains the function call.)
This works as a macro (sub). But it appears that a UDF (function) is
not permitted to modify cells of either the active worksheet or even
another worksheet.
I just want to confirm that this cannot be done in a UDF. Or is there
some way that I can do it?
I know that I could duplicate all of the formula calculations within
the UDF. But I do not want to hardcode the formulas in VB. Instead,
I want the flexibility of changing the formulas in one place, namely
the worksheet.
I believe I could use Evaluate to execute each formula within the VB
function. I will work with that idea. But I am concerned that it
will be a lot slower than Excel.
Are there good alternatives that I have overlooked?