在 VBA ArrayList 中搜索元素 [英] Search for an element in the VBA ArrayList
问题描述
我希望你很棒!我想搜索 VBA ArrayList 并获取索引号,问题是,使用 For 循环,您只能获取完全匹配的索引.我拥有大部分搜索元素(在红色框中突出显示)并且我想获取在蓝色框中突出显示的元素,有什么办法可以在 VBA 中做到这一点?
I hope you are great! I want to search through a VBA ArrayList and get the index number, the problem is, with For loop, you can only get the exact matches' index. I have the most of my search element (highlighted in the red box) and I want to get the elements which highlighted in the blue box, is there any way to do this in VBA?
推荐答案
您可以使用内置函数 InStr
来查找一个字符串在另一个字符串中的匹配项.
You can use the in-built function InStr
to find an occurrence of one string inside another.
在你的情况下改变这个:
In your case change this:
If list(j) = search_element Then
致:
If InStr(1, list(j), search_element) > 0 Then
InStr
返回list(j)
中search_element
的位置.如果位置高于 0,则找到该字符串.如果它是 0
那么什么都没有找到.
InStr
returns the position of search_element
within list(j)
. If the position is above 0 then the string was found. If it is 0
then nothing was found.
因此,如果 search_element
出现在 list(j)
中的任何位置,则为 true
.
Therefore, this will be true
if search_element
occurs anywhere within list(j)
.
InStr
的文档是 这里.
这篇关于在 VBA ArrayList 中搜索元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!