Skip to content

Instantly share code, notes, and snippets.

@jaykilleen
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jaykilleen/66aa778a315495819c52 to your computer and use it in GitHub Desktop.
Save jaykilleen/66aa778a315495819c52 to your computer and use it in GitHub Desktop.
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 https://gist.github.com/jaykilleen/892d0f0eed87b9f8e6b0 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