How to use keyword to tag every row automatically

KellyWills

New Member
Joined
Mar 16, 2022
Messages
18
Office Version
  1. 365
Platform
  1. MacOS
Hi All,

I have a large set of data that requires me to tag each row based on 2 column. I think there's possibility of using IF but I'm not sure how to joint 2 column. Here's my listing:

Screenshot 2022-04-25 at 9.23.21 PM.png


The colored column is my intended outcome. Is there a possibility to get this outcome by using excel functions?

Screenshot 2022-04-25 at 9.24.26 PM.png


Thank you in advance
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Book1
ABCDEFG
1TagsDescNamefav 1fav 2TAGS
2AAppleAllyI love to eat appleI like to drink juiceA, D
3BStarfruitAdamI love starfruitB
4CStrawberryKellyI Like to eat appleI like to drink waterA, E
5DjuiceKarenI love strawberryI love milkC, F
6EWater
7FMilk
Sheet1
Cell Formulas
RangeFormula
G2:G5G2=TEXTJOIN(", ",1,IFERROR(INDEX(A:A,SORT(UNIQUE(IF(ISNUMBER(SEARCH($B$2:$B$7,E2&F2)),ROW($B$2:$B$7),10^10)))),""))
 
Upvote 0
Book1
ABCDEFG
1TagsDescNamefav 1fav 2TAGS
2AAppleAllyI love to eat appleI like to drink juiceA, D
3BStarfruitAdamI love starfruitB
4CStrawberryKellyI Like to eat appleI like to drink waterA, E
5DjuiceKarenI love strawberryI love milkC, F
6EWater
7FMilk
Sheet1
Cell Formulas
RangeFormula
G2:G5G2=TEXTJOIN(", ",1,IFERROR(INDEX(A:A,SORT(UNIQUE(IF(ISNUMBER(SEARCH($B$2:$B$7,E2&F2)),ROW($B$2:$B$7),10^10)))),""))
Thank you for your reply! Works like wonders!

Do you mind to explain how the formula works so that I could tailor it in future? Like why 10^10? I don't quite understand that.

Btw, is there possibility of removing duplicates? For example F2 shows apple juice & the outcome will be A, A, D. I'd like to remove the duplicates.

Thank you :)
 
Upvote 0
Thank you for your reply! Works like wonders!

Do you mind to explain how the formula works so that I could tailor it in future? Like why 10^10? I don't quite understand that.

Btw, is there possibility of removing duplicates? For example F2 shows apple juice & the outcome will be A, A, D. I'd like to remove the duplicates.

Thank you :)
Btw, following questions, if there alternatives for Unique function that can be substitute? I will be sharing the file with Excel 2016 user - where unique function isn’t available :/
 
Upvote 0
Btw, is there possibility of removing duplicates? For example F2 shows apple juice & the outcome will be A, A, D. I'd like to remove the duplicates.
Did you try? It shouldn't be duplicates.
 
Upvote 0
Btw, following questions, if there alternatives for Unique function that can be substitute? I will be sharing the file with Excel 2016 user - where unique function isn’t available :/
That's why everybody loves 365 (for UNIQUE, FILTER, LET....). Gives us a chance. Maybe somebody adapt it into older version.
 
Upvote 0
Works like wonders!
Are you sure?
Below I have used that formula in column G. Check the coloured rows as I don't believe you would want those results?

For your Excel 365 I have provided what I believe to be a more robust formula in column H.

If you want this to work in 2016 then I think you will need to use vba as 2016 worksheet functions do not lend themselves to "textjoin" type operations.
You could try this user-defined function & use it as in column I below.

VBA Code:
Function AddTags(rLookup As Range, rVals As Range) As String
  Dim Foods As Variant, Tags As Variant, itm As Variant
  Dim sTag As String
  Dim pos As Variant
  
  Tags = Application.Transpose(rLookup.Columns(1).Value)
  Foods = Application.Transpose(rLookup.Columns(2).Value)
  For Each itm In Split(Join(Application.Index(rVals.Value, 1, 0)))
    pos = Application.Match(itm, Foods, 0)
    If IsNumeric(pos) Then
      sTag = Tags(pos)
      If InStr(1, AddTags & ",", ", " & sTag & ",", vbTextCompare) = 0 Then AddTags = AddTags & ", " & sTag
    End If
  Next itm
  AddTags = Mid(AddTags, 3)
End Function

KellyWills.xlsm
ABCDEFGHI
1Tags
2AAppleI love to eat appleI like to drink juiceA, DA, DA, D
3BStarfruitI like pineappleA  
4CStrawberryI love starfruitBBB
5DJuiceI Like to eat appleI like to drink waterA, EA, EA, E
6EWaterI love strawberryI love milkC, FC, FC, F
7FMilkHorses like strawBerry is niceC  
8I like juiceTom likes milk & juiceD, FD, FD, F
Sheet1
Cell Formulas
RangeFormula
G2:G8G2=TEXTJOIN(", ",1,IFERROR(INDEX(A:A,SORT(UNIQUE(IF(ISNUMBER(SEARCH($B$2:$B$7,E2&F2)),ROW($B$2:$B$7),10^10)))),""))
H2:H8H2=TEXTJOIN(", ",1,FILTER(A$2:A$7,ISNUMBER(SEARCH(" "&B$2:B$7&" "," "&E2&" "&F2&" ")),""))
I2:I8I2=AddTags(A$2:B$7,E2:F2)
 
Upvote 0
I did not think about 'part' of tags word, like apple in pineapple or fruit in starfruit.
Simple tweak in main part in formula:
Excel Formula:
=TEXTJOIN(", ",1,IFERROR(INDEX(A:A,SORT(UNIQUE(IF(ISNUMBER(SEARCH(" "&$B$2:$B$7&" "," "&E2&" "&F2&" ")),ROW($B$2:$B$7),10^10)))),""))
as in yours in H2, made a job.
 
Upvote 0
Are you sure?
Below I have used that formula in column G. Check the coloured rows as I don't believe you would want those results?

For your Excel 365 I have provided what I believe to be a more robust formula in column H.

If you want this to work in 2016 then I think you will need to use vba as 2016 worksheet functions do not lend themselves to "textjoin" type operations.
You could try this user-defined function & use it as in column I below.

VBA Code:
Function AddTags(rLookup As Range, rVals As Range) As String
  Dim Foods As Variant, Tags As Variant, itm As Variant
  Dim sTag As String
  Dim pos As Variant
 
  Tags = Application.Transpose(rLookup.Columns(1).Value)
  Foods = Application.Transpose(rLookup.Columns(2).Value)
  For Each itm In Split(Join(Application.Index(rVals.Value, 1, 0)))
    pos = Application.Match(itm, Foods, 0)
    If IsNumeric(pos) Then
      sTag = Tags(pos)
      If InStr(1, AddTags & ",", ", " & sTag & ",", vbTextCompare) = 0 Then AddTags = AddTags & ", " & sTag
    End If
  Next itm
  AddTags = Mid(AddTags, 3)
End Function

KellyWills.xlsm
ABCDEFGHI
1Tags
2AAppleI love to eat appleI like to drink juiceA, DA, DA, D
3BStarfruitI like pineappleA  
4CStrawberryI love starfruitBBB
5DJuiceI Like to eat appleI like to drink waterA, EA, EA, E
6EWaterI love strawberryI love milkC, FC, FC, F
7FMilkHorses like strawBerry is niceC  
8I like juiceTom likes milk & juiceD, FD, FD, F
Sheet1
Cell Formulas
RangeFormula
G2:G8G2=TEXTJOIN(", ",1,IFERROR(INDEX(A:A,SORT(UNIQUE(IF(ISNUMBER(SEARCH($B$2:$B$7,E2&F2)),ROW($B$2:$B$7),10^10)))),""))
H2:H8H2=TEXTJOIN(", ",1,FILTER(A$2:A$7,ISNUMBER(SEARCH(" "&B$2:B$7&" "," "&E2&" "&F2&" ")),""))
I2:I8I2=AddTags(A$2:B$7,E2:F2)
Hi Peter,

Thank you for your VBA Code. I've tried to incorporate it with my excel but it seems not working (it shows blank). My tags are in different sheet, do I need to modify the code? my formula is already:

=AddTags(Tags!$A$2:$B$12,R2:S2)

Thank you
 
Upvote 0
My tags are in different sheet, do I need to modify the code? my formula is already:

=AddTags(Tags!$A$2:$B$12,R2:S2)
Having the data on two sheets should not be a problem. The question is what are the sheets and where is the data on them?
Your formula above indicates that the lookup table of tags/fruit is in columns A:B of sheet 'Tags' but post #1 indicates they are in columns A:B of sheet 'Listing'.
The above formula indicates the values to look in are in columns R:S of the sheet that the formula is on, post 1 has them in A:B

So, here is my sample workbook as I think you have it based on the post 9 formula.

Sheet Tags

KellyWills.xlsm
AB
1Tags
2AApple
3BStarfruit
4CStrawberry
5DJuice
6EWater
7FMilk
8
9
10
11
12
Tags


Sheet Data (but the name of this sheet is irrelevant)

KellyWills.xlsm
RST
1
2I love to eat appleI like to drink juiceA, D
3I like pineapple 
4I love starfruitB
5I Like to eat appleI like to drink waterA, E
6I love strawberryI love milkC, F
7Horses like strawBerry is nice 
8I like juiceTom likes milk & juiceD, F
Data
Cell Formulas
RangeFormula
T2:T8T2=AddTags(Tags!$A$2:$B$12,R2:S2)


If all of that seems correct and it is still not working for you then one possibility might be a Windows v Mac issue. I don't use a Mac so I cannot test in that environment. I am also not particularly familiar with Windows/Mac issues.

Can you confirm that the formula is resulting in a blank cell and no error message is received?
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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