when looking for a single char, instr seems to miss the occurance if the char occurs as the first or last position in the string.
i have a work around, just repeat the first and last terms in the string, or insert a pad space.
But why is this nessesary?
VB Code:
Public Function InStrW(ByRef LookIn As String, ByRef LookFor As String) As Boolean ' break up lookfor into words, compares each Dim arWS() As String Dim xx As Long Dim match As Boolean match = True arWS = Split(Trim(LookFor), " ") For xx = 0 To UBound(arWS) - 2 If InStr(LookIn, Trim(arWS(xx))) = 0 Then match = False Else Debug.Print "InstrW = True", (arWS(xx)) & "<", Str(xx), arWS(xx) & "<", "instr return: " & Str(InStr(LookIn, Trim(arWS(xx)))), LookIn, vbTab, LookFor Debug.Print Trim(arWS(xx)) match = True InStrW = True xx = UBound(arWS) - 2 Exit For End If 'term in string? Next xx InStrW = match End Function
(i am subtracting 2 due to the pad space i had to use)




Reply With Quote