Excel:将文本解析为公式

发布于 2024-08-21 23:53:08 字数 475 浏览 10 评论 0原文

我希望 Excel 公式的一部分是动态的,而不是单元格引用。

例如,假设在 A 列(单元格 A1:A99)中我有一堆数字,我想知道其中有多少数字大于 50。

如果我希望此计算是静态的,我可以简单地使用一个以下内容:

=COUNTIF($A$1:$A$99,">50")
=SUM(IF($A$1:$A$99>50,1,0))
=SUM(($A$1:$A$99>50)*1)

我提到这三个是因为我的实际公式很复杂,并且有点混合了第二个和第三个。 (毕竟,也许有些东西适用于 COUNTIF,但不适用于其他单元格。)

现在,我希望能够在另一个单元格中输入我的条件(例如 C1)。因此,如果我在 C1 中输入“>50”,我的计算将如上,但如果我输入“<100”,我将计算 A 列中有多少条目小于 100。

这可能吗? (我在 Windows XP 上使用 Excel 2003。)

I would like to have part of an excel formula be dynamic, other than a cell reference.

For instance, suppose that in column A (cells A1:A99) I have a bunch of numbers, and I want to know how many of those numbers are greater than 50.

If I wanted this calculation to be static, I could simply use one of the following:

=COUNTIF($A$1:$A$99,">50")
=SUM(IF($A$1:$A$99>50,1,0))
=SUM(($A$1:$A$99>50)*1)

I mention all three because my actual formula is hairy and a bit of a mix of the second and the third. (After all, perhaps something will work with COUNTIF but not with the others.)

Now, I want to be able to type my condition in another cell (say C1). So if I type ">50" in C1, my calculation will be as above, but if I type "<100" I will count how many entries of column A are less than 100.

Is this possible? (I am using Excel 2003 on Windows XP.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花伊自在美 2024-08-28 23:53:08

我可能缺少一些东西。
如果您

=COUNTIF($A$1:$A$99,C1)

输入任何单元格,然后在单元格 C1 中输入 >50 或 <100
你没有得到你想要的吗?

There may be something that I'm missing.
If you give

=COUNTIF($A$1:$A$99,C1)

in any cell, and then in cell C1 you type >50 or <100
don't you get what you want?

十年九夏 2024-08-28 23:53:08

使用INDIRECT

=INDIRECT(COUNTIF($A$1:$A$99,">50"))

=COUNTIF($A$1:$A$99,">50")

但是,正如您所确定的,前者,您可以在Excel单元格内生成!我一直这样做,对于这样的事情

Use INDIRECT

=INDIRECT(COUNTIF($A$1:$A$99,">50"))

is same as

=COUNTIF($A$1:$A$99,">50")

But, as you identified, the former, you can generate within the excel cells! I do it all the time, for such things.

梦魇绽荼蘼 2024-08-28 23:53:08

我通常通过添加另一列承载复杂逻辑表达式的结果来解决这个问题,就像

=AND(OR(C3<D3;E3>=100);A3=VLOOKUP(B3;Sheet2!$A$2:$B$212;2;FALSE))

这个公式位于 F 列的所有行中一样 - 注意:这里不需要 IF!

然后我使用 =SUMIF() 计算 E 列的复杂条件总和,就像

=SUMIF(F2:F57;TRUE;E2:E57)

我知道有些用户说“我不想改变我的设计。没关系;我的论点是我可以更好地控制条件,我可以工作条件与依赖于该条件的求和或其他函数分开,我可以过滤 TRUE 或 FALSE 的记录来查看子集,并快速概览公式是否有意义

希望有帮助祝你好运 MikeD

I usually solve this by adding another column carrying the result of a complex logical expression, like

=AND(OR(C3<D3;E3>=100);A3=VLOOKUP(B3;Sheet2!$A$2:$B$212;2;FALSE))

this formula is in all rows of -say- column F - note: no IF needed here!

then I calculate a complex conditional sum across column E using =SUMIF() like

=SUMIF(F2:F57;TRUE;E2:E57)

I know that some users say "I do not want to change my design. That's ok; my argument is that I have better control over the condition, I can work on the condition seperately from summing up or other functions that rely on that condition, and I can filter records for TRUE or FALSE to look at the subsets and have a rapid overview if the formula makes sense

hope that helps Good luck MikeD

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文