匹配2列,并从第三列产生
需要帮助以比较(匹配)2列中的2列,如果匹配的话,第二板的第三列返回值。
With Range("B3:B" & Range("A" & Rows.Count).End(xlUp).Row)
.Formula = "=INDEX($D:$D,MATCH(1,(Sheet1!B$1=Sheet2!$C:$C)*(Sheet1!$A3=Sheet2!$A:$A),0))"
.Value = .Value
End With
表1:
表2:
因此,尝试使用功能,但需要一个更好的代码,该代码应该更快。任何建议..
Need help to compare (match) 2 columns from 2 sheets and return value from 3rd column of 2nd sheet if it matches.
With Range("B3:B" & Range("A" & Rows.Count).End(xlUp).Row)
.Formula = "=INDEX($D:$D,MATCH(1,(Sheet1!B$1=Sheet2!$C:$C)*(Sheet1!$A3=Sheet2!$A:$A),0))"
.Value = .Value
End With
Sheet 1:
Sheet 2:
This Function is taking longer than usual if I place formula in each cell (for whole month). so trying this With function but needs a better code which should run faster. Any suggestions ..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用字典词典匹配列
Match Columns Using a Dictionary of Dictionaries
如果您拥有Excel 365,则可以使用过滤器轻松地做到这一点:
我在单元格4中的公式是:
拖动到右下,
如果您没有Excel 365,则可以使用complext公式:
请注意,零件
sumproduct( - ($ a $ 2:$ a $ 13 = $ f4)* - ($ c $ 2:$ c $ c $ 13 = g $ 2)*fila($ d $ 2:$ d $ 13))
将返回数据所在的位置的绝对行号,因此您需要在索引中返回整个列或正确提取的索引(这就是为什么我从第1行(包括标头)中选出的原因是索引的第一个参数)。If you have Excel 365 you can make this easily with FILTER:
My formula in cell G4 is:
Drag to right and down
If you don't have Excel 365 you can do it with a complext formula:
Notice that the part
SUMPRODUCT(--($A$2:$A$13=$F4)*--($C$2:$C$13=G$2)*FILA($D$2:$D$13))
will return the absolute row number of where the data is located so in INDEX you need to reference the whole column or substract properly (that's why I chose from row 1 including headers as first argument of INDEX).这使用阵列公式同时填充B3:E6
This uses an array formula to populate B3:E6 simultaneously