Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ARRAY SEARCH PROBLEM !!!
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
ARRAY SEARCH PROBLEM !!!
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 jay dean wrote: 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 . . . And ArrB contains: ArrB(0)= 10,B,CC ArrB(1)= C,A,FF ArrB(2)= 44,KL,MN ArrB(3)= 79,88,B . . . Then I want to take ArrB(0),ArrB(1),ArrB(2),ArrB(3) and compare EACH to ArrA(0). If ALL the elements in any ArrB(x) are found in ArrA(0) then a messgBOx will show those found to be subsets. In this case, only elements of ArrB(1) are all found in Arr(0)... so we'll have Msgbox 'C,A,FF found' Then the macro will compare ArrB(0),ArrB(1),ArrB(2),ArrB(3) with ArrA(1). In this case, only elements of ArrB(3) can all be found in ArrA(1), so message box shows "79,88,B found'. Then we will compare all the ArrB to ArrA(2), ArrA(3), etc.. whenever ALL elements of ANY ArrB slot(s) are found in ANY element in ArrA, the Msgbox shows up with the subsets names. I think this will be a little tough but I am looking for a solution with minimum loops or even no loops (if at all possible). Any help will be appreciated. Thanks Jay Dean *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
search array | Excel Worksheet Functions | |||
search an array for values contained in another array | Excel Programming | |||
Array problem: Key words-Variant Array, single-element, type mismatch error | Excel Programming | |||
Array problem: Key words-Variant Array, single-element, type mismatch error | Excel Programming | |||
SEARCH EXCEL ARRAY FOR NON-VOIDS AND ENTER INTO ANOTHER ARRAY, | Excel Programming |