Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Excel VbA to find a value in an array. Use as find_in_arry
'Just copy the function below into a new module
'I usually call this module 'functions'
'You can then call anywhere in your scripts `find_in_array("dummy text", some_array)
'Where some_array might be something like ["camp","light bulb", "dummy text")
'This function will return TRUE if it finds the value in the array
`checkout for other functions that I like to add into my 'functions' module
Function find_in_array(FindMe As String, myArray() As String)
Dim C As String
Dim ItemFound As Boolean
Dim MatchCase As Boolean
MatchCase = False
' Perform search
C = Chr$(1)
ItemFound = InStr(1, C & Join(myArray, C) & C, C & FindMe & C, 1 + MatchCase)
If ItemFound Then find_in_array = True
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment