[英]How to count all multiple cells in Excel
I am trying to count All the multiple colors assigned for one project in Excel column. 我正在尝试计算在Excel列中为一个项目分配的所有多种颜色。 I tried the below formula but its counting the only value which I requested.
我尝试了以下公式,但是它计算了我要求的唯一值。
=COUNTIFS(C10:C17, G19, E10:E17, H19)
. =COUNTIFS(C10:C17, G19, E10:E17, H19)
。
**Project List Colors**
Project a Black
Project b Brown
Project c Red
Project d Orange
Project a Yellow
Project b Brown
Project c Red
Project e Black
Project f Green
In the above table, if selected a cell contain Project a, it should display 1 Black and 1 Yellow. 在上表中,如果选中一个包含Project a的单元格,则应显示1 Black和1 Yellow。 If selected a cell contain project b, it should display 2 brown.
如果选择一个包含项目b的单元格,则应显示2棕色。
Edit: Colors are values its not a actual color or background color. 编辑:颜色是其实际值或背景颜色的值。
You can use the UDF 您可以使用UDF
Function modifiedCountif(Rng1 As Range, Criteria1 As Range, Rng2 As Range)
Dim i As Long
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
Dim Result As String
Result = ""
For i = 1 To Rng1.Count
If Rng1.Cells(i, 1) = Criteria1 Then
On Error Resume Next
dict.Add Rng2.Cells(i, 1).Value, Application.WorksheetFunction.CountIfs(Rng1, Criteria1, Rng2, Rng2.Cells(i, 1))
End If
Next
Dim key As Variant
For Each key In dict.Keys
Result = Result & dict(key) & " " & key & ", "
Next key
modifiedCountif = Left(Result, Len(Result) - 2)
dict.RemoveAll
End Function
Where Rng1
is the range of Project List 其中
Rng1
是项目列表的范围
Criteria1
is the project you are searching for. Criteria1
是您要搜索的项目。
Rng2
is the Range for colors Rng2
是颜色范围
I am not sure about your actual data ranges so following is my test setup. 我不知道你的真实数据范围,从而以下是我的测试设置。
Project List is in range C10:C18
. 项目列表在
C10:C18
范围内。
Colors List is in range E10:E18
. 颜色列表在
E10:E18
范围内。
Input cell which holds a single value like Project b
is I2
. 像
Project b
这样拥有单个值的输入像元是I2
。
Then formula will be (to be committed by pressing CTRL + SHIFT + ENTER simultaneously while in edit mode. If applied correctly, Excel will wrap formula by {}). 然后将是公式(在编辑模式下,同时按CTRL + SHIFT + ENTER可以提交公式。如果正确应用,Excel将用{}包装公式)。
=IFERROR(INDEX($E$10:$E$18,SMALL(IF($C$10:$C$18=$I$2,IF(MATCH($C$10:$C$18&$E$10:$E$18,$C$10:$C$18&$E$10:$E$18,0)=(ROW($E$10:$E$18)-9),ROW($E$10:$E$18),2097153),2097153),ROWS($A$1:A1))-9),"")
You will have to adjust the ranges to suit. 您将不得不调整范围以适合。 Attention must be given to number 9 which is used because data starts at row 10. It should be always (n-1) assuming n is row where your data begins!
必须注意使用数字9,因为数据从第10行开始。它应该始终为(n-1),假设n是数据开始的行!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.