XLA routines: EE_IsInArray
EE_IsInArray is a function to check whether a value is in an array
Function EE_IsInArray(arr As Variant, valueToCheck As String, _ Optional exactMatch As Boolean = True) As Boolean Dim wordList As String Dim startPosition As Long Dim nextCommaPosition As Long Dim matchedTerm As String 'http://excelexperts.com/xla-routines-eeIsInArray for updates on this function If UBound(Filter(arr, valueToCheck)) > -1 Then wordList = Join(arr, ",") ' start from the allegedly matched term .... startPosition = InStr(wordList, valueToCheck) ' get position of the comma after the allegedly matched term ... nextCommaPosition = InStr(startPosition + 1, wordList, ",") ' the alleged "match" is in between If nextCommaPosition = 0 Then matchedTerm = Mid$(wordList, startPosition) Else matchedTerm = Mid$(wordList, startPosition, _ nextCommaPosition - startPosition) End If If exactMatch Then EE_IsInArray = (StrComp(valueToCheck, matchedTerm) = 0) Else EE_IsInArray = (StrComp(valueToCheck, matchedTerm) <> 0) End If End If End Function
»
- Nick's blog
- Login or register to post comments
- 2954 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago