-2

Presume there are several elements in array which are duplicate.

array = [1,2,4,6,1,6,9,12]

I need to find all the indexes of 1 which means 0 and 4. Can anyone show me how to do that?

1 Answers1

0

The following takes an array of values as the first parameter, and the value to find as the second, and returns an array of indexes where the value was found:

Function FindIndexesOfElement(valuesArray, elmToFind) 
  Set indexes = CreateObject("Scripting.Dictionary") 

  For i = LBound(valuesArray) to UBound(valuesArray)
    If elmToFind = valuesArray(i) Then
      indexes(i) = True 
    End If
  Next 

  FindIndexesOfElement = indexes.Keys 
End Function
willman
  • 1,191
  • 1
  • 7
  • 20