问题
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