简体   繁体   English

多个条件唯一值

[英]Multiple criteria unique values

在此处输入图片说明 I have two issues that I am looking for help with. 我有两个需要帮助的问题。

The first, is to create a dynamic list of unique ID numbers for items matching "Horse" in column J on Sheet 2!, "Ball" in column I on Sheet 2!, and that do not contain the word dog in column A on Sheet 2! 第一种是为在工作表2!的J列中的“马”,在工作表2!的I列中的“球”匹配且在“工作”的A列中不包含“狗”字的项目创建唯一ID号的动态列表。工作表2! In the example below, this would return the ID numbers 48 and 56 在下面的示例中,这将返回ID号48和56

The second, is that while I have calculated the number of assets meeting this criteria (3) , using 第二个是,尽管我计算了满足此条件(3)的资产数量,

=COUNTIFS(Sheet2!$A:$A, " <>Dog ", Sheet2!$J:$J, "Horse", Sheet2!$I:$I, "Ball") = COUNTIFS(Sheet2!$ A:$ A,“ <> Dog ”,Sheet2!$ J:$ J,“ Horse”,Sheet2!$ I:$ I,“ Ball”)

I would like to calculate the number of unique entries as well, which would be 2 in the example provided. 我也想计算唯一条目的数量,在提供的示例中为2。

So I understand you resolved your second issue. 因此,我了解您已经解决了第二个问题。 As for the dynamic list, I believe the fastest way to do this would be using macro. 至于动态列表,我相信最快的方法是使用宏。 If you want your unique list of ids to place in the Sheet3 it would look like this: 如果要将唯一的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

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

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