ARRAY SEARCH PROBLEM !!!

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
 
K

keiji kounoike

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top