Last active
August 29, 2015 14:17
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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