在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.
因此,如果 list(j)
中的任何地方出现 search_element
,则这将为 true
.
Therefore, this will be true
if search_element
occurs anywhere within list(j)
.
InStr
的文档为此处.
这篇关于在VBA ArrayList中搜索元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!