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
- 2981 reads
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago