首页 > 解决方案 > Mathematical formula evaluation in Excel

问题描述

I want to evaluate a mathematical function existing in some cell in Microsoft Excel with some value from other cell, let say that in the A1 cell the user writes “X^2+2X+5” and in the cell A2 writes 3, I want to obtain the result on A3 equals to 20 (the function evaluation for X=3). The idea is writing a macro that has two parameters, the first one, the expression and the other the variable value. Where can I find the code (VB Excel Macro) for doing this without starting from zero? Thanks.

标签: excelvbamatheval

解决方案


您可以使用Application.Evaluate,例如

application.Evaluate(replace([A1],"X",[A2]))

您必须将公式更新为X^2+2*X+5


推荐阅读