vba 如何在一个单元格中查找每个逗号分隔值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43253677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:24:59  来源:igfitidea点击:

How to vlookup each comma separated value in one cell?

excelexcel-vbaexcel-formulavlookupexcel-2016vba

提问by compski

I have worksheet A:

我有工作表A:

a

一种

I have another worksheet (WS) B:

我有另一个工作表(WS)B:

enter image description here

在此处输入图片说明

What I want:
I wanna use a Vlookupformula at cell C3 with the formula like this:

我想要什么:
我想Vlookup在单元格 C3 中使用一个公式,公式如下:

=VLOOKUP(B2,b!A2:B3,2,FALSE)

However:
I don't know how to make it look up multiple comma separated values (csv) in one cell(Note that there are cells that can go up to 10 csv)

但是:
我不知道如何让它在一个单元格中查找多个逗号分隔值 (csv)(请注意,有些单元格可以达到 10 个 csv)

Logic wise, cell C3 of WS A should :

从逻辑上讲,WS A 的单元格 C3 应该:

  • Lookup value B2
  • From the table array of WS B
  • Looping through cell A2 of WS B, it should check for "1-ABC", "2-ABC", "3-ABC".
  • Since it finds a match at "3-ABC" then C3 will return the Unique Acc ID at B2 of WS B
  • Then hopefully I can drag down the formula to many many records...
  • 查找值 B2
  • 来自WS B的表数组
  • 循环通过 WS B 的单元格 A2,它应该检查“1-ABC”、“2-ABC”、“3-ABC”。
  • 由于它在“3-ABC”处找到匹配项,因此 C3 将返回 WS B 的 B2 处的唯一帐户 ID
  • 然后希望我可以将公式拖到许多记录中...

Can this be done using formula or it better to do it via VBA? If VBA, how can I do this?

这可以使用公式来完成还是通过 VBA 更好地完成?如果是 VBA,我该怎么做?

回答by P??

You can use the asterisks as wildcard like that

您可以像这样使用星号作为通配符

=VLOOKUP("*" & B2 & "*",b!A2:B3,2,FALSE)