简体   繁体   English

Excel VBA:在命名表中的特定列上进行vLookup,如果它与多个条件和通配符匹配,则替换值

[英]Excel VBA: vLookup on a specific column in a Named Table and replacing value if it matches with multiple criteria and wildcard

I'd like to create a macro that will take the name of the resource and do a vLookup (or similar action) on another table to find the matching resource manager's info, then replace the NULL manager name and email address in the first table with the manager info that corresponds to that Resource. 我想创建一个将使用资源名称并在另一个表上执行vLookup(或类似操作)以查找匹配的资源管理器信息的宏,然后将第一个表中的NULL管理器名称和电子邮件地址替换为与该资源相对应的经理信息。 The end goal is to complete my table with the Generic Resource's manager and their email address. 最终目标是与通用资源的管理员及其电子邮件地址一起填写我的表格。

I have a table on Sheet1 named "Resources": 我在Sheet1上有一个名为“资源”的表:

"Resources" table “资源”表

I also have a table on Sheet2 named "ManagerLookup": 我在Sheet2上还有一个名为“ ManagerLookup”的表:

"ManagerLookup" table “ ManagerLookup”表

How can I loop through each Resource Name in my table to match the resources up with their correct manager? 如何遍历表中的每个资源名称,以使资源与其正确的管理器匹配? I'm only looking to replace the manager fields for which I have a match on the Resource Name. 我只想替换在“资源名称”上与之匹配的经理字段。 I can't only perform vlookup on rows with a "NULL" Manager name, since my data does not only use "NULL" for missing manager names (sometimes it's different). 我不能只对管理器名称为“ NULL”的行执行vlookup,因为我的数据不仅对缺少的管理器名称使用“ NULL”(有时会有所不同)。

I've searched for hours and can't find anything, but I need a clean way to do this. 我已经搜索了几个小时,什么也找不到,但是我需要一种干净的方法来完成此操作。 Also worth noting is that the "Resources" table doesn't ever get larger than about 500 rows so processing time is not a factor here. 同样值得注意的是,“资源”表的行数永远不会超过500行,因此此处的处理时间不是一个因素。 I'm using Excel 2016. 我正在使用Excel 2016。

如果前两个字母对于经理是唯一的(例如您的示例),请从“经理”表中删除#号,并在资源表中使用以下公式:

=IFERROR(VLOOKUP(LEFT(A2,2)&"*",Sheet2!A:B,2,FALSE),"Not found")

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

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