用EXCEL中的公式查表

用EXCEL中的公式查表,excel,lookup,Excel,Lookup,我正在制作一个电子表格,在单元格中使用不同的公式。这些公式会根据调用的公式ID进行更改。例如,公式查找表如下所示: Formula ID|Formula __________+________________ 1 | y=x+2 __________+________________ 2 | y=x^2 - 34 __________+________________ 3 | ... __________+________________

我正在制作一个电子表格,在单元格中使用不同的公式。这些公式会根据调用的公式ID进行更改。例如,公式查找表如下所示:

Formula ID|Formula
__________+________________
    1     |  y=x+2
__________+________________
    2     |  y=x^2 - 34
__________+________________
    3     |  ...
__________+________________
    ...   |  ...
__________+________________
   |   A   |   B   |   C
___+_______+_______+________
 1 |   2   |   *** | =if(A1=2, use formula #2, which is "=B1^2-34", "")
                     =if(A1=1, use formula #1, which is "=B1+2", "")
___+_______+_______+________
 2 |   1   |   *** | =if(A1=2, use formula #2, which is "=B2^2-34", "")
                     =if(A1=1, use formula #1, which is "=B2+2", "")
___+_______+_______+________
 3 |   2   |   *** | =if(A1=2, use formula #2, which is "=B3^2-34", "")
                     =if(A1=1, use formula #1, which is "=B3+2", "")
=eval(VLOOKUP(A1,Sheet1!$A$1:$B$100,2,0),B1)
我的主要工作表如下所示:

Formula ID|Formula
__________+________________
    1     |  y=x+2
__________+________________
    2     |  y=x^2 - 34
__________+________________
    3     |  ...
__________+________________
    ...   |  ...
__________+________________
   |   A   |   B   |   C
___+_______+_______+________
 1 |   2   |   *** | =if(A1=2, use formula #2, which is "=B1^2-34", "")
                     =if(A1=1, use formula #1, which is "=B1+2", "")
___+_______+_______+________
 2 |   1   |   *** | =if(A1=2, use formula #2, which is "=B2^2-34", "")
                     =if(A1=1, use formula #1, which is "=B2+2", "")
___+_______+_______+________
 3 |   2   |   *** | =if(A1=2, use formula #2, which is "=B3^2-34", "")
                     =if(A1=1, use formula #1, which is "=B3+2", "")
=eval(VLOOKUP(A1,Sheet1!$A$1:$B$100,2,0),B1)
“A”列显示公式ID。“B”列是“x”的输入。“C”列是函数“y”


我只能找到如何使用查找表中的值,而不是公式。请帮忙。非常感谢。

您可以使用简单的用户定义功能:

Function eval(formula As String, r As Range)
    If Left(formula, 1) = "y" Then
        formula = Right(formula, Len(formula) - 1)
    End If
    eval = Evaluate(Replace(formula, "x", r.Address))
End Function
然后像这样在
C1
中调用它:

Formula ID|Formula
__________+________________
    1     |  y=x+2
__________+________________
    2     |  y=x^2 - 34
__________+________________
    3     |  ...
__________+________________
    ...   |  ...
__________+________________
   |   A   |   B   |   C
___+_______+_______+________
 1 |   2   |   *** | =if(A1=2, use formula #2, which is "=B1^2-34", "")
                     =if(A1=1, use formula #1, which is "=B1+2", "")
___+_______+_______+________
 2 |   1   |   *** | =if(A1=2, use formula #2, which is "=B2^2-34", "")
                     =if(A1=1, use formula #1, which is "=B2+2", "")
___+_______+_______+________
 3 |   2   |   *** | =if(A1=2, use formula #2, which is "=B3^2-34", "")
                     =if(A1=1, use formula #1, which is "=B3+2", "")
=eval(VLOOKUP(A1,Sheet1!$A$1:$B$100,2,0),B1)

其中
Sheet1$A$1:$B$100
使用公式存储您的表格

而不使用VBA您需要明智地选择()

在C1中,输入:

=CHOOSE(A1,B1^2-34,B1+2)
然后抄下来

展开公式以包含所需数量的案例