Matching two words in a list

mdgud

New Member
Joined
Aug 22, 2009
Messages
2
Hope someone can help me with my issue. I have two lists of folders, for example:

\Animal\Brown\Dog\Chihuahua
\Animal\Brown\Small\Pug
\Animal\Dogs\Brown\Small\Corgi
\Animal\Dogs\Black\Poodle
\Animal\White\Dogs\Bichon_Frise
\Animal\Dogs\White\Bichon_Frise

and

1.0 Dogs\1.1 White\1.1.1 Poodle
1.0 Dogs\1.1 White\1.1.2 Chihuahua
1.0 Dogs\1.1 White\1.1.3 Bichon_Frise
1.0 Dogs\1.2 Brown\1.2.1 Chihuahua
1.0 Dogs\1.2 Brown\1.2.2 Pug
1.0 Dogs\1.2 Brown\1.2.3 Corgi
1.0 Dogs\1.2 Brown\1.2.4 Poodle
1.0 Dogs\1.3 Black\1.3.1 Poodle

I need to identify the correct folder in the second list based on the folder path of the first list. The first list is not well organized, but two words in the first list can be used to identify the correct folder in the second list.

I first used "Split" to get each subfolder name, but I'm not sure how to search every value in the second list to find two matching words. My code so far:

Code:
Sub Testit()
    Dim OPath As String
    Dim NPath As String
    Dim fld As Variant
    Dim x As Integer
    Dim i As Long
    Dim Folder(1 To 10)
    
    For x = 1 To 6
        OPath = Cells(x, 1).Value 'Original Folder Path
        fld = Split(OPath, "\") '
        For i = 0 To UBound(fld)
            Debug.Print fld(i) 'subfolder name
        Next i
    
    '??? how do I find two words that match the folders in the second list ???
    
    Next x
End Sub
Thanks for your help
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi, With your Data layed out as Shown .
The code will produce results as shown in Msgbox.
See what you make of the Results !!!!
Code:
[COLOR="RoyalBlue"][B]Column(A)                       [/B][/COLOR] [COLOR="RoyalBlue"][B]Column(B)                             [/B][/COLOR]
\Animal\Brown\Dogs\Chihuahua     1.0 Dogs\1.2 Brown\1.2.1 Chihuahua    
\Animal\Brown\Small\Pug          1.0 Dogs\1.1 White\1.1.1 Poodle       
\Animal\Dogs\Brown\Small\Corgi   1.0 Dogs\1.1 White\1.1.2 Chihuahua    
\Animal\Dogs\Black\Poodle        1.0 Dogs\1.1 White\1.1.3 Bichon_Frise 
\Animal\White\Dogs\Bichon_Frise  1.0 Dogs\1.2 Brown\1.2.2 Pug          
\Animal\Dogs\White\Bichon_Frise  1.0 Dogs\1.2 Brown\1.2.3 Corgi        
                                 1.0 Dogs\1.2 Brown\1.2.4 Poodle       
                                 1.0 Dogs\1.3 Black\1.3.1 Poodle
Code:
[COLOR="Navy"]Sub[/COLOR] MG23Aug32
[COLOR="Navy"]Dim[/COLOR] Rng1 [COLOR="Navy"]As[/COLOR] Range, Rng2 [COLOR="Navy"]As[/COLOR] Range, Dn1 [COLOR="Navy"]As[/COLOR] Range, Dn2 [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Sp [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] SDn1, C [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer,[/COLOR] Txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng1 = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]Set[/COLOR] Rng2 = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn1 [COLOR="Navy"]In[/COLOR] Rng1
    SDn1 = Split(Dn1, "\")
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn2 [COLOR="Navy"]In[/COLOR] Rng2
            C = 0
            [COLOR="Navy"]For[/COLOR] Sp = 1 To UBound(SDn1)
                [COLOR="Navy"]If[/COLOR] InStr(Dn2, SDn1(Sp)) [COLOR="Navy"]Then[/COLOR]
                    C = C + 1
                [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]Next[/COLOR] Sp
                [COLOR="Navy"]If[/COLOR] C = 3 [COLOR="Navy"]Then[/COLOR]
                    Txt = Txt & Dn1 & "-----" & Dn2 & Chr(10)
                [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] Dn2
[COLOR="Navy"]Next[/COLOR] Dn1
MsgBox "The following Matches were Found :-" & Chr(10) & Txt
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,697
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top