Excel公式来引用多个列中的多个条件

我正在尝试创build一个公式来返回在Excel中的行号。 基本上我有两个不同的表,我想链接。 在参考列下的员工部分,我想要放置一个公式,如果符合某些标准,将引用一个数字。

例如,我想能够取2256(麻木为汤姆),并searchbuild筑物表中的“分配”列进行匹配,然后查看紧挨着它的单元格是否表示是否超时(x是加class),然后我想要它返回数组B3:B7中相应行的参考编号,以便与员工编号相匹配,但不是加class。 如果它找不到符合这两个标准的东西,我需要它返回数字0.在这种情况下,我想汤姆有一个参考数字报告1,liz它有一个参考4,和凯西显示3。琥珀应该保持空白。

Building Ref Post Start End assign overtime 1 sh 1600 2400 2256 2 sn 600 1400 2057 x 3 sh 1000 1800 2107 4 sd 1400 2200 2057 5 dc 700 1500 2256 x Employee Name Numb Start End Post Reference tom 2256 day eve sh ?? Liz 2057 day eve sd ?? Amber 2952 day eve none ?? kathy 2107 day eve sh ?? 

有人可以帮助这个公式? 我已经尝试过sumproduct,index,match,if和and的版本,并且总是收到错误。 谢谢。

使用您的样本数据,公式将是:

 =IFERROR(INDEX($A$2:$A$6,MATCH(1,INDEX(($E$2:$E$6=B10)*($F$2:$F$6=""),),0)),"") 

但是,只返回第一场比赛的参考号码。 有没有可能发生一次以上的事件? 如果是的话,结果是什么?

如果它只能发生一次,也许一个简单的SUMIFS会对你更好:

 =SUMIFS($A$2:$A$6,$E$2:$E$6,B10,$F$2:$F$6,"") 

然后将表单格式化为不显示0,或使用自定义格式来隐藏它们: 0;0;;@

当然,一如既往,调整范围以适应

没有不公正的答案,我相信它运作良好。 你的问题有很多解决办法,我的不一定是最好的。 但是…您可能想尝试写一个VBmacros来完成任务。 如果你不知道,macros是一个简单的编程types,学习如何使用macros在Excel中打开一个有用的可能性的整个世界。 (如果您有时间和倾向)使用macros,您可以标记variables,检查结果并轻松进行debugging,也可以使用未来的增强function对其进行修改。 您可以使用Developer-> Visual Basic子菜单运行macros。 运行和debuggingmacros很容易,很有趣…试试看

 Public Sub Employee_Not_Overtime_Check() ' Dim iMaxEmployee As Long Dim iMaxBuilding As Long Dim irow As Long Dim iEmpNum As Long Dim iReference As Integer ' Initialisation, stop screen refresh during macro execution Application.ScreenUpdating = False Application.DisplayAlerts = False iMaxBuilding = Sheets("Building").UsedRange.Rows.Count iMaxEmployee = Sheets("Employee").UsedRange.Rows.Count ' For debug, setting limits smaller iMaxBuilding = 10 iMaxEmployee = 10 ' Loop through the Employee Records, for each one check their overtime status irow = 2 Do While irow <= iMaxEmployee Sheets("Employee").Select iEmpNum = Cells(irow, 2).Value Call CheckOvertime(iEmpNum, iMaxBuilding, iReference) Sheets("Employee").Select Cells(irow, 6).Value = iReference irow = irow + 1 Loop Application.ScreenUpdating = True Application.DisplayAlerts = True End Sub Function CheckOvertime(ByVal iEmpNum As Long, ByVal iMaxBuilding As Long, ByRef iReference As Integer) Dim irow As Long Sheets("Building").Select iReference = 0 For irow = 2 To iMaxBuilding If Cells(irow, 5).Value = iEmpNum Then If Cells(irow, 6).Value <> "x" Then iReference = Cells(irow, 1).Value Exit For End If End If Next irow End Function