ARRAY SEARCH PROBLEM !!!

  • Thread starter Thread starter jay dean
  • Start date Start date
J

jay dean

Hi -

I have 2 arrays: ArrA and ArrB. Each slot in each array contains
characters delimited by comma ",". I need to check if for every slot
content in ArrA, all members of any slot(s) in ArrB are there. ArrA and
ArrB don't necessarily have the same size or length.I just used array
lengths of 3 for ArrA and 4 for ArrB for simplicity but the actual
array slots can be lengthier.

Example:
If ArrA contains:
ArrA(0)= A,BB,C,FF,X
ArrA(1)= 88,VV,J,B,79
ArrA(2)= U,KL,MN,6,44
 
This is one way, though this doesn't satisfy your request for having
minimum loops or even no loops, but rather having maximum loops.

Sub Searchtest()
Dim ArrA(2), ArrAA
Dim ArrB(3), ArrBB
Dim i As Long, j As Long, k As Long
Dim found As Boolean

ArrA(0) = "A,BB,C,FF,X"
ArrA(1) = "88,UU,J,B,79"
ArrA(2) = "U,KL,MN,6,44"
ArrB(0) = "10,B,CC"
ArrB(1) = "C,A,FF"
ArrB(2) = "44,KL,MN"
ArrB(3) = "79,88,B"

For i = 0 To UBound(ArrA)
For j = 0 To UBound(ArrB)
found = True
ArrAA = Split(ArrA(i), ",")
ArrBB = Split(ArrB(j), ",")
For k = 0 To UBound(ArrBB)
If IsError(Application.Match(ArrBB(k), ArrAA, 0)) Then
found = False
Exit For
End If
Next
If found Then
MsgBox ArrB(j) & " Found in ArrA(" & i & _
") = { " & ArrA(i) & " }"
End If
Next
Next
End Sub

Keiji
 
Back
Top