简体   繁体   English

跨多个列的索引匹配

[英]Index match across multiple columns

I am trying to do an index match with the index looking in column B (Date) and the match is to find a works order number (eg example 1, example 2) from a separate sheet and match to the tab screen shown below.我正在尝试与 B 列(日期)中的索引进行索引匹配,匹配是从单独的工作表中找到工作订单号(例如示例 1、示例 2)并匹配下面显示的选项卡屏幕。

Here is a copy of the table range I am trying to gather a match from这是我试图从中收集匹配的表格范围的副本

In my head it would look like so =INDEX(B:B,MATCH("A1",E2:BP200,0)), however it wont look across all the range to find a match.在我看来,它看起来像 =INDEX(B:B,MATCH("A1",E2:BP200,0)),但是它不会查看所有范围以找到匹配项。

I have a formula that technically works which is "=@IFNA(IFS(ISNUMBER(MATCH([@Batch],'Production Plan':E,E,0)):INDEX('Production Plan',B,B:MATCH([@Batch],'Production Plan'.EE0))"...repeated for each column. However this makes the calculations incredibly slow.我有一个在技术上有效的公式,它是 "=@IFNA(IFS(ISNUMBER(MATCH([@Batch],'Production Plan':E,E,0)):INDEX('Production Plan',B,B:MATCH ([@Batch],'Production Plan'.EE0))"...对每一列重复。但是这使得计算速度非常慢。

Any help would be hugely appreciated.任何帮助将不胜感激。

One solution could be to create a VBA function using "range.find", where "range" is your E:BP area.一种解决方案是使用“range.find”创建 VBA function,其中“range”是您的 E:BP 区域。

So you could make the function below, to return the row number where it finds the first match to your order number.因此,您可以在下面创建 function,以将找到第一个匹配项的行号返回到您的订单号。 The way the function is written, it would return the row number within the entire worksheet (eg it should tell you "5" if you look for "Example 1"). function 的编写方式,它将返回整个工作表中的行号(例如,如果您查找“示例 1”,它应该告诉您“5”)。 It is also set up to return -1 if there is an error or it can't find your search term, so you might want to make better error handling.如果出现错误或找不到您的搜索词,它还设置为返回 -1,因此您可能希望进行更好的错误处理。

So my suggested use here would be INDEX(B:B,rowmatch_exact("A1",E1:BP200,"columns")) or INDEX(B:B,rowmatch_exact("A1",E1:BP200,"rows")).所以我在这里建议使用 INDEX(B:B,rowmatch_exact("A1",E1:BP200,"columns")) 或 INDEX(B:B,rowmatch_exact("A1",E1:BP200,"rows")) .

Function rowmatch_exact(sought As Variant, range As range, searchdirection As String) As Integer

On Error GoTo ErrorDone

If searchdirection = "columns" Then
    rowmatch_exact = range.Find(what:=sought, searchorder:=xlByColumns, LookIn:=xlValues, lookat:=xlWhole).Row
ElseIf searchdirection = "rows" Then
    rowmatch_exact = range.Find(what:=sought, searchorder:=xlByRows, LookIn:=xlValues, lookat:=xlWhole).Row
Else
    GoTo ErrorDone
End If

GoTo Done:
ErrorDone:
rowmatch_exact = -1
Done:

End Function

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

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