简体   繁体   English

在 VBA 中,如何检查字符串是否包含在单元格中找到的许多字符串中的任何一个?

[英]In VBA, how to check if a string contains any of many strings found in a cell?

I'm struggling a bit to figure this one out, so I thought I'd ask here.我正在努力解决这个问题,所以我想我会在这里问。

I have a cell with a LOT of words in it.我有一个单元格,里面有很多单词。 I also have another cell with a compound word in it.我还有另一个单元格,里面有一个复合词。 Say, as an example, that the compound word is PineappleTree, and my cell with the words has "Pineapple" in it, along with maybe 1000 other words.举例来说,复合词是 PineappleTree,我的单元格中包含“Pineapple”,可能还有 1000 个其他词。 The goal here is to be able to get a formula that should return TRUE or 1 or some value that indicates that part of the compound word was found or not in the other cell.这里的目标是能够获得一个公式,该公式应返回 TRUE 或 1 或指示在另一个单元格中找到或未找到部分复合词的某个值。 I could maybe cycle through each word with Instr but it wouldn't be very efficient I don't think, so I wanted to see if there was a better way to do this first.我也许可以用 Instr 循环遍历每个单词,但我认为它不会很有效,所以我想先看看是否有更好的方法来做到这一点。

Thanks in advance: :)提前致谢: :)

I am not aware of a simpler solution... I would use split to create an array of the words from the "cell with words", loop though that and search with instr , breaking the loop when one found, as a small optimization.我不知道一个更简单的解决方案......我会使用split从“带有单词的单元格”中创建一个单词数组,然后循环并使用instr进行搜索,找到时打破循环,作为一个小的优化。

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

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