简体   繁体   English

Excel公式可计算单个单元格中的多种可能组合

[英]Excel formula to count multiple possible combinations in single cell

Newbie-ish with Excel here. Excel新手在这里。 I'm trying to keep things simple for long term ease of use since most at my job don't know much of anything with Excel or anything with VBA. 我试图使事情长期保持简单易用,因为大多数工作对Excel或VBA都不了解。

I'm looking to have a formula count cells containing up to 4 different codes (TRM2-TRM5) out of 32 possible codes. 我正在寻找一个公式来对包含32种可能的代码中最多4个不同代码(TRM2-TRM5)的单元格进行计数。 However, the cell these combinations are entered in is not required to be in any specific order. 但是,并不需要以任何特定顺序输入这些组合的单元格。

Such as: 如:

B1 (TRM2, R2, TRM3) B1 (TRM2,R2,TRM3)

B2 (TRM2, PN1, DC5, TRM4) B2 (TRM2,PN1,DC5,TRM4)

B3 (PN1, IPA5c, HW2, TRM5) B3 (PN1,IPA5c,HW2,TRM5)

B4 (PN1, HW2, R2) B4 (PN1,HW2,R2)

The desired result of the formula is a count of 3 该公式的预期结果是计数为3

I don't need to count the individual number of times the TRM codes appear. 我不需要计算TRM代码出现的次数。 Just the number of cells they appear in a range (such as B1:B99 ). 只是它们出现在一个范围内的单元格数(例如B1:B99 )。

I've tried COUNTIFS but quickly discovered I'd have to have a COUNTIFS for each possible combination of the 4 codes. 我已经尝试过COUNTIFS但是很快发现我必须为4种代码的每种可能组合都设置一个COUNTIFS

So far the simplest way is to use multiple instances of conditional formatting that highlights the cells that contain one of the four codes and do a visual count. 到目前为止,最简单的方法是使用条件格式化的多个实例,这些实例将突出显示包含四个代码之一的单元格并进行可视计数。 All the examples I've read don't have multiple values in one cell so I'm not sure how to tackle it. 我读过的所有示例在一个单元格中都没有多个值,因此我不确定如何解决它。

For those that are curious, the purpose is error reporting for issues missed in an audit. 对于那些好奇的人,目的是针对审计中遗漏的问题进行错误报告。

Thanks for the help! 谢谢您的帮助!

Given your example, you can do this with a helper column. 在您的示例中,您可以使用帮助器列来完成此操作。

Either hard code an array constant with the codes to find, or enter them in separate cells someplace. 可以使用要查找的代码对一个数组常量进行硬编码,或者在某个地方将它们输入到单独的单元格中。 I did the latter and named that range theCodes . 我做了后者并命名为theCodes范围。

Use this array formula in the helper column: 在帮助器列中使用以下数组公式:

C1: =MIN(FIND(theCodes,B1&CONCAT(theCodes)))<LEN(B1)

and fill down as far as needed 并根据需要填写

This will return TRUE or FALSE depending on whether any of the codes are present in the cell. 根据单元中是否存在任何代码,这将返回TRUEFALSE

Then, a simple COUNTIF will count all the TRUE 's 然后,一个简单的COUNTIF将计算所有TRUE

 D1: =COUNTIF($C:$C,TRUE)

在此处输入图片说明

NOTE: To enter/confirm an array formula , hold down ctrl + shift while hitting enter . 注意:要输入/确认数组公式 ,请在按Enter的同时按住ctrl + shift If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar. 如果正确执行此操作,Excel会将括号{...}放在在公式栏中看到的公式周围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM