Sorry if this is a stupid question but i've been racking my brain for a couple of days now and i can't seem to come up with a solution to this.
I have a list of phrases and a list of keywords that need to be searched, extracted and replaced.
For example i have the following list of keywords in sheet 1 column A that need to be extracted and replaced with the keywords in column B.
red      -     orange
blue     -     violet
green    -     pink
yellow   -     brown
And in sheet 2 I have a list of phrases in column A.
The girl with blue eyes had a red scarf.
I saw a yellow flower.
My cousin has a red car with blue rims and green mirrors.
And I want to extract in column B the keywords that are matched for every phrase in the exact order that they appear like so:
COLUMN A                                                        COLUMN B
The girl with blue eyes had a red scarf.                        violet, orange
I saw a yellow flower.                                          brown
My cousin has a red car with blue rims and green mirrors.       orange, violet, pink
Is there any way this can be achieved either by formula or VBA? Also this needs to be usable with Excel 2016 so i can't use fancy functions like "TEXTJOIN".
Thank you everyone in advance!
Cheers!
L.E.
I was able to find some code that almost does what I need it to do but it does not keep the correct order.
Is there anyway it could be modified to generate the desired results? Unfortunately I'm not that good with VBA. :(
Sub test()
Dim datacount As Long
Dim termcount As Long
datacount = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
termcount = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To datacount
    dataa = Sheets("Sheet1").Cells(i, "A").Text
    
    result = ""
            
    For j = 1 To termcount
    
        terma = Sheets("Sheet2").Cells(j, "A").Text
        termb = Sheets("Sheet2").Cells(j, "B").Text
        
        If InStr(dataa, terma) > 0 Then
        
             
        If result = "" Then
           
           result = result & termb
           
        Else
        
            result = result & ", " & termb
            
        End If
            
        End If
        
    Next j
    
       Sheets("Sheet1").Cells(i, "B").Value = result
    
    Next i
End Sub
 
    










 
    
