作为财务模型用户的完整性检查,我需要一个方程式来判断是否已经考虑了每个产品层次结构。这意味着Tab1上B1:B100范围内的每个值都应该在Tab2的C2:c200范围内计算。如果满足此条件,则公式应为“完成”,如果不是“不完整”。有谁知道如何创建这样的函数?
=if(Every value in tab1!b1:b100 has a match in tab2!c2:c200, "Complete", "Incomplete")
答案 0 :(得分:4)
计算匹配数量,我们可以使用:
=SUMPRODUCT(COUNTIF(Sheet1!B1:B100,Sheet2!C2:C200))
测试第一张纸中的所有内容是否都可以在第二张纸中找到:
=SUMPRODUCT(COUNTIF(Sheet1!B1:B100,Sheet2!C2:C200)) = COUNTA(Sheet1!B1:B100)
或
=SUMPRODUCT(COUNTIF(Sheet1!B1:B100,Sheet2!C2:C200)) = 100
如果没有空白或重复。
答案 1 :(得分:1)
只是添加VBA解决方案
Sub columnsMatch()
Dim filters As Variant
filters = Application.Transpose(Worksheets("Sheet2").Range("C2:C200").Value)
With Worksheets("Sheet1").Range("b1:b100") 'reference "Sheet1" sheet range B1:B100
.AutoFilter Field:=1, Criteria1:=filters, Operator:=xlFilterValues ' filter referenced range with values from "Sheet2" sheet range C2:C200
.Parent.Range("M1").Value = IIf(Application.WorksheetFunction.Subtotal(103, .Cells) = .Count And Not IsError(Application.Match(.Cells(1, 1).Value, filters, 0)), "Complete", "Incomplete")
.Parent.AutoFilterMode = False ' remove filters
End With
End Sub