Excel counts the number of times a value appears in a group of columns but counts only one instance of the name per row

别说谁变了你拦得住时间么 提交于 2019-12-22 17:38:09

问题


I need to find the number of times a name appears on this list but I only want to count one instance of the name one time for each row without counting the duplicate name in the row.

For instance: I have the following in a range...

Red     Bill    Jack    Ruby    Bill
Blue    Ruby    Ivan    Raul    Ted
Green   Ted     James   Rick    Ted
Red     Ted     Phil    Ruby    Bill

And in this worksheet, I want to count the number of instances of the name Bill and get the answer of 2 because Bill's name shows up in two rows. In the same respect, If I choose to count the name Ted, the answer should be 3 because Ted's name shows up in three rows.


回答1:


Use OFFSET with SUMPRODUCT. In F7 (per supplied image) as,

=SUMPRODUCT(SIGN(COUNTIF(OFFSET(B$1:E$1, ROW($1:$4)-1, 0), E7)))

The SIGN function turns any positive number to 1 for each row. ROW(1:4) cycles through each of the rows.




回答2:


Assuming you put your name of choice, e.g. "Ted", in G1, array formula**:

=SUM(0+(MMULT(0+(A1:E4=G1),TRANSPOSE(COLUMN(A1:E4)))>0))

Regards

**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).




回答3:


A non-vba solution with a helper column in column F.

Column F formula =IF(COUNTIF(B1:E1,$I$1)>0,1,0)

J2 formula =SUM(F1:F4)

change I1 as needed for name.



来源:https://stackoverflow.com/questions/43374008/excel-counts-the-number-of-times-a-value-appears-in-a-group-of-columns-but-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!