Search for an element in the VBA ArrayList

爷,独闯天下 提交于 2021-02-10 18:23:56

问题


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?


回答1:


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

To:

If InStr(1, list(j), search_element) > 0 Then

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.

Therefore, this will be true if search_element occurs anywhere within list(j).

The documentation for InStr is here.



来源:https://stackoverflow.com/questions/59134858/search-for-an-element-in-the-vba-arraylist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!