行与列的比较(命名范围)

Comparison of row with a column (named range)

我的数据:

TABLE 1 人 1 人 2 人 3 人 4 人 5 人 6 第 7 个人 人 8
星期一 一个 B C D E E F F
星期二 B F D C E E F 一个
星期三 C D 一个 F E E F F
地点
一个
B
C
D

我的问题: 我想比较是否每天命名范围 Place 中的所有值都在 Monday, Tuesday, Wednesday,... 的行内,如果缺少某些值,这些值是哪一个。
因此,对于 Wednesday,它应该使用 IF 公式或您的任何建议给出 "B" missing"E""F" 不在 Place 中,那些应该被忽略。

到目前为止我尝试了什么: 研究总是让我比较 2 列而不是行和列。
我试过这样的数组函数($B3:$I3 == "Monday row" == "row1"):

=INDEX(Place;SMALL(IF(ISERROR(MATCH(Place;$B3:$I3;0));(ROW(Place)-MIN(ROW(Place))+1);"");ROWS($A:A1)))

Error: Many "helper" columns needed for inidividual rows to compare. Also "#NUM!" values even if all vlaues from Place occur or just one is missing.

我开始使用许多 COUNTIF 公式,例如

=COUNTIF(row1;INDEX(Place;1))+COUNTIF(row1;INDEX(Place;2))+COUNTIF(row1;INDEX(Place;3))+COUNTIF(row1;INDEX(Place;4))

当所有值都出现时给我一个 "4",如果部分或全部缺失则降低值。但是我如何才能将获取这些数字与“查看”缺少哪些值导致“低于 4”的数字联系起来?

我认为这个 UDF 会给你想要的结果。

Function Check(Data As Range) As String
    ' 296
    
    ' Data specifies one row from the table excl column #1
    Dim Fun()       As String               ' function return value
    Dim i           As Long                 ' index to Fun()
    Dim Places      As Variant              ' array of range "Place"
    Dim R           As Long                 ' loop counter; Places
    Dim Match       As Variant              ' result of Match() function
    
    ' this command will slow down your workbook.
    '   If inconvenient (too sluggish), remove it.
    ' If removed, the UDFs in the worksheet may not recalculate as you expect.
    '   Click "Calculate Now" on the ribbon's 'Formulas' tab to update.
    Application.Volatile
    
    ' the named range "Places" must exist in the worksheet
    ' in the sample it's B10:B13
    Places = ActiveSheet.Range("Places").Value
    ReDim Fun(UBound(Places))
    
    For R = 1 To UBound(Places)
        Match = Application.Match(Places(R, 1), Data, 0)
        If IsError(Match) Then
            i = i + 1
            Fun(i) = Places(R, 1)
        End If
    Next R
    
    If i Then
        Fun(0) = "Missing: "
    Else
        Fun(0) = "All present"
    End If
    ReDim Preserve Fun(i)
    Check = Replace(Join(Fun, ", "), ",", vbNullString, 1, 1)
End Function

代码必须粘贴到标准代码模块。您必须插入它,默认情况下它的名称类似于“Module1”,您可以更改该名称。不要使用任何现有的代码模块。通过输入类似于以下的语法从工作簿中的任何位置调用该函数:=Check(C3:J3)。这里 C3:J3 定义 table 的倒数第二列,不包括“星期一”,结果将根据 Places.

范围评估此范围内列出的项目

如果您 Excel 2019 年或以上,您可以像这样将 Textjoin 与 Countif 结合使用:

=TEXTJOIN(",",,IF(COUNTIF(B2:I2,Places)=0,Places,""))

其中 Places 是命名范围 $A$6:$A$9。

您必须重复很多公式或使用单独的列使其输入“全部存在”或“缺失”

=IFS(SUM(COUNTIF(B2:I2,Places))=ROWS(Places),"All present",SUM(COUNTIF(B2:I2,Places))=0,"All missing",TRUE,"Missing "&TEXTJOIN(",",,IF(COUNTIF(B2:I2,Places)=0,Places,"")))

除非你有 Excel 365,你可以在其中使用 Let 来避免重复:

=LET(counts,COUNTIF(B2:I2,Places),
total,SUM(counts),
IFS(total=ROWS(Places),"All present",total=0,"All missing",TRUE,"Missing "&TEXTJOIN(",",,IF(counts=0,Places,""))))

如果您没有 Textjoin,我认为除了使用单独的 Countif 或 Matches 之外别无选择。