Check for match comma separated values in multiple cells

Howard_Roark

New Member
Joined
Apr 8, 2023
Messages
5
Office Version
  1. 2021
Platform
  1. MacOS
Hi,
I have always been able to figure out how to solve an excel problem by looking at forums but this one is impossible for me to figure out, so please help.

I have an excel sheet where I need to show which dog food is appropriate for which specific dog breed.
I have a table for pet breeds and another table with the pet food.
I need the column D, that is for each product, to be populated with all the breeds in one line (one cell), separated by columns.

The match is supposed to be based on size (XS, S, M, L, XL) and white color (yes or no).
Therefore, if any of the values separated by commas in cell B1 is present in a row of column H and C1 matches with column G at the same row, return from that row the value in column F. Run for each row for the D column in the product sheet.

Attached is an example of the Sheet.

I can also reconstruct the sheet if necessary.

Thank you

Screenshot 2023-04-08 at 12.25.55.png
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi,

Very interesting Challenge which will excite ALL contributors ...!!! Congratulations !!!

My personal inclination would be to design a tailor-made UDF ... especially since you do need to concatenate all "compatible" breeds in Column D ...
 
Upvote 0
Hi,

Very interesting Challenge which will excite ALL contributors ...!!! Congratulations !!!

My personal inclination would be to design a tailor-made UDF ... especially since you do need to concatenate all "compatible" breeds in Column D ...
I am also afraid that UDF would be the only way to go. This is above my skill level.

The concatenation is the only part I was able to figure out by using the =TEXTJOIN. Tried it with =IF function but it doesn't work properly. The challenge is the correct matching mechanism with the commas and returning of the appropriate cell value and applied for the whole table.

BTW: ChatGPT also could't figure it out...
 
Upvote 0
BTW: ChatGPT also could't figure it out...

The poor ChatGPT ... :biggrin:

It is Work-In-Progress ... You should be waiting for Version 5 ( availability Q4-2023 )

Rumor has it it will be a really major improvement ;)
 
Upvote 0
Since you have tackled your own solution with a macro, both your columns B and H will require you to use the VBA Split function ...
 
Upvote 0
See if this comes close to what you're looking for. Put the Function in a standard module. Note the use of it in both a table & range below the code. Basically, it works like this:
Excel Formula:
=Woof(<cells to the left>,<table or range to the right absolute references>)

VBA Code:
Function Woof(a, b As Range) As String
    Application.Volatile
    Dim i As Long, j As Long, Prods, Dogs As String
    Prods = Split(CStr(a(2)), ", ")
    Dim c: c = b
    For i = LBound(c, 1) To UBound(c, 1)
        For j = LBound(Prods) To UBound(Prods)
            If InStr(CStr(c(i, 3)), CStr(Prods(j))) And c(i, 2) = a(3) Then
                If Dogs = "" Then
                    Dogs = c(i, 1)
                Else
                    Dogs = Dogs & ", " & c(i, 1)
                End If
                Exit For
            End If
        Next j
    Next i
    Woof = Dogs
End Function

Woof.xlsm
ABCDEFGH
1Product NameAppropriate Breed SizesAppropriate for White ColorAppropriate for these BreedsBreedWhite ColorBreed Size
2Product AS, XS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAffenpinscherYesL, XL
3Product BM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAfghan HoundNoL, XL
4Product CS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAfricanisYesL, XL
5Product DL, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAidiNoL, XL
6Product EL, M, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAiredale TerrierYesL, XL
7Product FM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAkbashNoL, XL
8Product GM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAkitaYesM
9Product HL, M, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAksaray MalaklisiNoXL
10Product IM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAlano EspanolYesS
11Product JM, LNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAlapaha Blue Blood BulldogNoXL
12
13
14Product NameAppropriate Breed SizesAppropriate for White ColorAppropriate for these BreedsBreedWhite ColorBreed Size
15Product AS, XS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAffenpinscherYesL, XL
16Product BM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAfghan HoundNoL, XL
17Product CS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAfricanisYesL, XL
18Product DL, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAidiNoL, XL
19Product EL, M, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAiredale TerrierYesL, XL
20Product FM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAkbashNoL, XL
21Product GM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAkitaYesM
22Product HL, M, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAksaray MalaklisiNoXL
23Product IM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAlano EspanolYesS
24Product JM, LNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAlapaha Blue Blood BulldogNoXL
Sheet1
Cell Formulas
RangeFormula
D2:D11D2=Woof(Table1[@[Product Name]:[Appropriate for White Color]],Table2)
D15:D24D15=Woof(A15:C15,$F$2:$H$11)
 
Upvote 0
I was able to figure it out manually. I am sure the is a more elegant solution that would implement the first (intermediate) step into the second step:

1) I split the sizes column into individual columns:
=TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",LEN($A2))),(J$1-1)*LEN($A2)+1,LEN($A2)))

Where J1 has "1" and K1 has "2" and so on. I did the same for both columns with sizes.

2) I checked all the columns with the sizes agains each other if they match and if white color matches and combined all the result into one line separated by comma:
=TEXTJOIN(", ",TRUE,FILTER(Table1[Breed],(IF(R2="",0,(Table1[1]=R2)+(Table1[2]=R2)+(Table1[3]=R2))+IF(S2="",0,(Table1[1]=S2)+(Table1[2]=S2)+(Table1[3]=S2))+IF(T2="",0,(Table1[1]=T2)+(Table1[2]=T2)+(Table1[3]=T2))+IF(U2="",0,(Table1[1]=U2)+(Table1[2]=U2)+(Table1[3]=U2))+IF(V2="",0,(Table1[1]=V2)+(Table1[2]=V2)+(Table1[3]=V2)))*(Table1[White Color]=Table2[@White Color]),""))

seems to work
 
Upvote 0
Hi,

Kevin's solution ... if I may underline it, is far more elegant, far more efficient and far less likely to be disrupted ... :)
 
Upvote 0
Another option without adding the extra columns.
Fluff.xlsm
ABCDEFGH
1Product NameAppropriate Breed SizesAppropriate for White ColorAppropriate for these BreedsBreedWhite ColorBreed Size
2Product AS, XS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAffenpinscherYesL, XL
3Product BM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAfghan HoundNoL, XL
4Product CS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAfricanisYesL, XL
5Product DL, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAidiNoL, XL
6Product EL, M, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAiredale TerrierYesL, XL
7Product FM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAkbashNoL, XL
8Product GM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAkitaYesM
9Product HL, M, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAksaray MalaklisiNoXL
10Product IM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAlano EspanolYesS
11Product JM, LNoAfghan Hound, Aidi, AkbashAlapaha Blue Blood BulldogNoXL
Summary
Cell Formulas
RangeFormula
D2:D11D2=LET(s,TRIM(MID(SUBSTITUTE(B2,",",REPT(" ",100)),SEQUENCE(10,,,100),100)),f,TRANSPOSE(FILTER(" "&s&",",s<>"")),TEXTJOIN(", ",,FILTER($F$2:$F$11,(MMULT(SIGN(ISNUMBER(SEARCH(f," "&$H$2:$H$11&","))),SEQUENCE(COLUMNS(f),,,0)))*($G$2:$G$11=C2))))
 
Upvote 0
Solution
Another option without adding the extra columns.
Fluff.xlsm
ABCDEFGH
1Product NameAppropriate Breed SizesAppropriate for White ColorAppropriate for these BreedsBreedWhite ColorBreed Size
2Product AS, XS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAffenpinscherYesL, XL
3Product BM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAfghan HoundNoL, XL
4Product CS, M, LYesAffenpinscher, Africanis, Airedale Terrier, Akita, Alano EspanolAfricanisYesL, XL
5Product DL, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAidiNoL, XL
6Product EL, M, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAiredale TerrierYesL, XL
7Product FM, L, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAkbashNoL, XL
8Product GM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAkitaYesM
9Product HL, M, XLNoAfghan Hound, Aidi, Akbash, Aksaray Malaklisi, Alapaha Blue Blood BulldogAksaray MalaklisiNoXL
10Product IM, L, XLYesAffenpinscher, Africanis, Airedale Terrier, AkitaAlano EspanolYesS
11Product JM, LNoAfghan Hound, Aidi, AkbashAlapaha Blue Blood BulldogNoXL
Summary
Cell Formulas
RangeFormula
D2:D11D2=LET(s,TRIM(MID(SUBSTITUTE(B2,",",REPT(" ",100)),SEQUENCE(10,,,100),100)),f,TRANSPOSE(FILTER(" "&s&",",s<>"")),TEXTJOIN(", ",,FILTER($F$2:$F$11,(MMULT(SIGN(ISNUMBER(SEARCH(f," "&$H$2:$H$11&","))),SEQUENCE(COLUMNS(f),,,0)))*($G$2:$G$11=C2))))
Works beautifully
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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