Excel MAXIF功能或仿真? [英] Excel MAXIF function or emulation?

查看:298
本文介绍了Excel MAXIF功能或仿真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 excel 中有一个中等大小的数据集我想从中提取B列中值的最大值,但仅提供满足特定标准的A列中的单元格。

I have a moderately sized dataset in excel from which I wish to extract the maximum value of the values in Column B, but those that correspond only to cells in Column A that satisfy certain criteria.

所需的功能类似于 SUMIF COUNTIF ,但是这两个都不需要返回数据。没有一个 MAXIF 函数;如何模拟一个?

The desired functionality is similar to that of SUMIF or COUNTIF, but neither of those return data that is necessary. There isn't a MAXIF function; how do I emulate one?

推荐答案

您可以使用数组公式。在要计算最大值的单元格中输入: = Max(If([test],[if true],[if false]),其中用方括号中的值替换为test,如果为true则返回什么,如果为false则返回什么,例如:

You can use an array formula.In the cell in which you want the max calculated enter: =Max(If([test],[if true],[if false]) where you replace the values in square brackets with the test, what to return if true and what to return if false. For example:

=MAX(IF(MOD(A2:A25,2)=0,A2:A25,0)

在此公式中,如果值除以2,则返回列A中的值。注意,我使用一系列单元格我的比较和值如果是false而不是单个单元格。

In this formula I return the value in column A if the value divided by 2 has no remainder. Notice that I use a range of cells in my comparison and in the value if false rather than a single cell.

现在,在编辑单元格的同时,按Ctrl + Shift + Enter(按住Ctrl键和一起移动,然后按Enter键)。

Now, while still editing the cell, hit Ctrl+Shift+Enter (hold down the Ctrl key and the Shift together and then hit enter).

这将创建一个数组公式,用于范围内的每个值。

This creates an array formula that acts on each value in the range.

编辑 BTW,您是否要以编程方式或手动方式执行此操作?如果以编程方式,则使用什么环境? VBA?C#?

EDIT BTW, did you want to do this programmatically or manually? If programmatically, then what environment are you using? VBA? C#?

编辑如果通过VBA,您需要使用FormulaArray属性和R1C1引用:

EDIT If via VBA, you need to use the FormulaArray property and R1C1 references like so:

Range("A1").Select
Selection.FormulaArray = "=MAX(IF(MOD(R[1]C:R[24]C,2)=0,R[1]C:R[24]C,0))"

这篇关于Excel MAXIF功能或仿真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆