vba Excel MATCH 字符限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20503745/
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 00:53:51  来源:igfitidea点击:

Excel MATCH character limit

excelexcel-vbavba

提问by Maple

I use the following formula =INDEX(Dict!A:A,MATCH(A2,Dict!A:A,0),1)but MATCH only works with text below 256 characters. Any way to overcome this limitiation?

我使用以下公式=INDEX(Dict!A:A,MATCH(A2,Dict!A:A,0),1)但 MATCH 仅适用于 256 个字符以下的文本。有什么办法可以克服这种限制?

回答by barry houdini

To accommodate partial matches use SEARCHlike this:

为了适应部分匹配,使用SEARCH如下:

=INDEX(Dict!A:A,MATCH(TRUE,INDEX(ISNUMBER(SEARCH(A2,Dict!A:A)),0),0))

=INDEX(Dict!A:A,MATCH(TRUE,INDEX(ISNUMBER(SEARCH(A2,Dict!A:A)),0),0))

That will work to return a value > 256 characters but A2 can't be > 256 characters

这将返回一个大于 256 个字符的值,但 A2 不能大于 256 个字符

回答by Oscar Ca?ón

You can use the LDMP look-up method, taking advantage of the concat formula available since the Excel 2016.

您可以使用 LDMP 查找方法,利用自 Excel 2016 以来可用的 concat 公式。

={CONCAT(IF(Value=A:A;B:B;"")}

Note that it is a matrix formula so you must enter it CTRL + SHIFT + ENTER. Additionally the formula returns not only the first value but all the matching values.

请注意,它是一个矩阵公式,因此您必须按 CTRL + SHIFT + ENTER 输入它。此外,该公式不仅返回第一个值,还返回所有匹配的值。

回答by Mark W

There is another way to do this, if you don't mind the messiness of a helper column, and your original formula is not being repeated in subsequent rows (i.e. matching cells A3, A4, A5...). The helper column can of course be hidden to keep DICT looking pretty.

还有另一种方法可以做到这一点,如果您不介意辅助列的混乱,并且您的原始公式不会在后续行中重复(即匹配单元格 A3、A4、A5...)。辅助栏当然可以隐藏以保持 DICT 看起来漂亮。

  1. Insert (or use) a column (say B:B) next to A:A in DICT!, and populate it with a simple formula "=A1=SHEET1!A$2" (SHEET1 being the name of your source/original sheet), which will populate the column with TRUE and FALSE values, indicating which rows (if any) in DICT match to A2.

  2. The match syntax then changes from "MATCH(A2,Dict!A:A,0)" to "MATCH(TRUE,Dict!B:B,0)".

  1. 在 DICT! 中的 A:A 旁边插入(或使用)一列(比如 B:B),并用一个简单的公式“=A1=SHEET1!A$2”填充它(SHEET1 是您的源/原始工作表的名称) ,这将使用 TRUE 和 FALSE 值填充列,指示 DICT 中的哪些行(如果有)与 A2 匹配。

  2. 然后匹配语法从“MATCH(A2,Dict!A:A,0)”变为“ MATCH(TRUE,Dict!B:B,0)”。

Note: I know this works in principle as I have just done it, but if I added a typo in retrofitting it to the example provided, apologies, however the principle should be easy to follow.

注意:我知道这在原则上是有效的,因为我刚刚完成了它,但是如果我在将它改造成提供的示例时添加了一个错字,抱歉,但是原则应该很容易遵循。