*** Code Correction ***
In a parallel posting, Keiji observed a problem with the function I posted.
Here is a modified function that fixes the problem.
Function MyFun(S1 As String, S2 As String) As Boolean
Dim i As Long, S1FixedUp As String, sTokens2() As String
S1FixedUp = "," & Replace(S1, " ", "") & ","
sTokens2 = Split(Replace(S2, " ", ""), ",")
For i = 0 To UBound(sTokens2)
If InStr(S1FixedUp, "," & sTokens2(i) & ",") = 0 Then Exit Function
Next
If i 0 And i = UBound(sTokens2) + 1 Then MyFun = True
End Function
--
Rick (MVP - Excel)
"Rick Rothstein" wrote in message
...
Using the structure Ron posted (along with my modified line of code), I
just use the Replace function on *each* argument's string values to remove
any and all spaces from both of them...
Function MyFun(S1 As String, S2 As String) As Boolean
Dim i As Long
Dim sTokens2() As String
sTokens2 = Split(Replace(S2, " ", ""), ",")
For i = 0 To UBound(sTokens2)
If InStr("," & S1 & ",", "," & Replace(sTokens2(i), _
" ", "") & ",") = 0 Then Exit Function
Next i
If i 0 And i = UBound(sTokens2) + 1 Then MyFun = True
End Function
--
Rick (MVP - Excel)
"jay dean" wrote in message
...
Thanks Rick, Per Jessen, Keiji, and Ron.
A few comments:
Keiji, your code works just as the others but it doesn't seem to do a
binary compare. For example, using your code: MyFun("GG,TY,D","gg,D")
will evaluate to "True" even though the token "GG" < "gg".
I think agree with Rick's comments on Ron's code. In effect, it works
like the Find() function. It doesn't look for exact matches explicitly,
but also includes 'hits' that match partially.
Rick, is there a way to modify your code so that it ignores spaces as
the Trim() function will do? Example: Right now, using your code,
MyFun("YH,L,GT,W,B,Q", " B")
or MyFun("YH,L,GT,W,B,Q", " B,W ") produces "False" because of the
spaces in the tokens, even though "B" and "W" are elements of the first
input. Is there a way to have this ignore the spaces and ouput to "True"
as long as all the characters themselves match regardless of any spaces
in the tokens?
Thanks
Jay
*** Sent via Developersdex http://www.developersdex.com ***