2014-02-25 45 views
0

我想创建一个公式来返回excel中的行号。基本上我有两个不同的表格,我想链接。在参考列下的员工部分,我想要提出一个公式,如果符合某些标准,它将引用一个数字。Excel公式引用多个列中的多个条件

例如,我希望能够取2256(麻木为tom)并搜索建筑物表中的“分配”列以查找匹配,然后查看紧靠其的单元是否表示超时或不是(x是超时),然后我希望它返回数组B3中对应行的参考编号:B7,用于符合员工编号但不超时的班次。如果它找不到符合这两个标准的东西,我需要它返回数字0.在这种情况下,我希望汤姆的参考数字报告为1,即它有一个参考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版本,并且总是收到错误。谢谢。

回答

2

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

=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;;@

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

0

不尊重公式答案,我相信它工作得很好。 你的问题有很多解决方案,我的不一定是最好的。 但是... 您可能想尝试编写一个VB宏来完成任务。 如果你不知道,宏是一种简单的编程类型,学习如何使用宏可以在excel中打开一个有用可能性的整个世界。 (如果您有时间和倾向) 使用宏可以为变量添加标签,检查结果并轻松进行调试,以及使用任何未来的增强功能对其进行修改。 您可以使用Developer-> Visual Basic子菜单运行宏。 运行和调试宏很容易和有趣...试试吧,看看

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