【问题标题】:Multiple criteria unique values多个条件唯一值
【发布时间】:2019-05-15 04:27:43
【问题描述】:

我有两个问题需要帮助。

首先,为与表 2! 的 J 列中的“马”、表 2! 的第一列中的“球”匹配且不包含单词 dog 的项目创建唯一 ID 号的动态列表第 2 页上的 A 列!在下面的示例中,这将返回 ID 号 48 和 56

第二个,虽然我已经计算出满足这个标准的资产数量 (3) ,但使用

=COUNTIFS(Sheet2!$A:$A, "", Sheet2!$J:$J, "马", Sheet2!$I:$I, "球" )

我还想计算唯一条目的数量,在提供的示例中为 2。

【问题讨论】:

  • 这个公式适用于获取唯一值 {=SUM(IF(FREQUENCY(IF(--(ISNUMBER(SEARCH("Dog",$A$2:$A$8)))=0, IF($I$2:$I$8="球",IF($J$2:$J$8="马",MATCH($C$2:$C$8,$C$2:$C$8,0))) ),ROW($C$2: $C$8)-ROW($C$2)+1),1))}

标签: arrays excel-formula duplicates countif


【解决方案1】:

所以我知道你解决了你的第二个问题。 至于动态列表,我相信最快的方法是使用宏。 如果您希望将唯一的 id 列表放置在 Sheet3 中,则如下所示:

Sub list()

Dim pet, toy, animal As String
Dim ID, row As Integer

'pointing where list of unique ids will begin
Sheets("Sheet3").Activate
Range("A2").Select

'pointing beginig of the table with data
Sheets("Sheet2").Activate
Range("A2").Select

'loop to look for the ids
Do While IsEmpty(ActiveCell) = False
    pet = ActiveCell.Value
    ID = ActiveCell.Offset(0, 2).Value
    toy = ActiveCell.Offset(0, 8).Value
    animal = ActiveCell.Offset(0, 9).Value

    If ((pet <> "dog") And (toy = "ball") And (animal = "horse")) Then
        Sheets("Sheet3").Activate
        ActiveCell.Value = ID
        ActiveCell.Offset(1, 0).Select
        Sheets("Sheet2").Activate
    End If

    ActiveCell.Offset(1, 0).Select
Loop

'removing duplicates from our list
Sheets("Sheet3").Activate
row = ActiveCell.row
ActiveSheet.Range("$A$2:$A$" & row).RemoveDuplicates Columns:=1, Header:=xlNo

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    • 2018-05-04
    • 2016-07-19
    • 1970-01-01
    相关资源
    最近更新 更多