Excel to find key words and paste the same in Criteria column

tinferns

Board Regular
Joined
Aug 18, 2009
Messages
150
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Team.. Need your help again. I believe it is possible for Excel to find key words as described by user and paste the same in the dedicated cell. And I also believe this can be done without using a Macro. Please help out on the below.. I prefer not to use Macro's if possible please.

Keyword and their expected output:

Key Words (NOT case sensitive): (This is just an example Key Word list.. actual one is approx. 20 items/values)Result
FlightFlight
FlightsFlight
TicketAir Ticket
Air TicketAir Ticket
Air TicketsAir Ticket
PNRPNR
PNR'sPNR
PNRsPNR

Below is an example (In some cases there are 2 key words used, Excel can choose the first key word in such cases)

DescriptionCriteriaExpected Result
ABC bought a flight ticket paying XXX amountFlight
XYZ bought 3 Air Tickets paying xxx amountAir Ticket
CDE bought 1 Air Ticket vide PNR - XXXXXXXAir Ticket

Hope to hear from you soon. Thanks.. M
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi, maybe this works (depending on your version)
Book1
ABCDEFGH
1DescriptionCriteriaKey WordsResult
2ABC bought a flight ticket paying XXX amountFlightFlightFlightIn Name ManagerFormula
3XYZ bought 3 Air Tickets paying xxx amountAir TicketFlightsFlightvXML="<text><a>"&SUBSTITUTE(Sheet1!$A1;" ";"</a><a>")&"</a></text>"
4CDE bought 1 Air Ticket vide PNR - XXXXXXXAir TicketTicketAir TicketvPosKeyWord=AGGREGATE(15;6;MATCH(tKeyWords[Key Words];FILTERXML(vXML;"//a");0);1)
5TicketsAir Ticket
6PNRPNR
7PNR'sPNR
8PNRsPNR
9
10
Sheet1
Cell Formulas
RangeFormula
B2:B4B2=INDEX(tKeyWords[Result],MATCH(FILTERXML(vXML,"/text/a["&vPosKeyWord&"]"),tKeyWords[Key Words],0))
 
Last edited:
Upvote 0
Or Power Query solution
- Loading both tables to PQ
- Save tKeyWords as connection only (jst used as lookup table)
- Convert the text range to a table named tText, and apply the following M-code
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="tText"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Description", type text}}),
    WordsAsTable = Table.AddColumn(#"Changed Type", "Words", each Table.FromList(Text.Split(Text.Lower([Description])," "), Splitter.SplitByNothing(),{"Words"})),
    MergeKeyWords = Table.AddColumn(WordsAsTable, "MatchKeyWords", each Table.NestedJoin([Words], {"Words"}, tKeyWords, {"Key Words"}, "tKeyWords", JoinKind.Inner)),
    CombineMatches = Table.AddColumn(MergeKeyWords, "ExtractKeyWords", each Table.Combine([MatchKeyWords][tKeyWords])[Result]),
    ExtractResults = Table.TransformColumns(CombineMatches, {"ExtractKeyWords", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    RemoveHelpers = Table.RemoveColumns(ExtractResults,{"Words", "MatchKeyWords"})
in
    RemoveHelpers

Book1
ABCD
1DescriptionKey WordsResult
2ABC bought a flight ticket paying XXX amountFlightFlight
3XYZ bought 3 Air Tickets paying xxx amountFlightsFlight
4CDE bought 1 Air Ticket vide PNR - XXXXXXXTicketAir Ticket
5TicketsAir Ticket
6PNRPNR
7PNR'sPNR
8PNRsPNR
9
10
11DescriptionExtractKeyWords
12ABC bought a flight ticket paying XXX amountFlight;Air Ticket
13XYZ bought 3 Air Tickets paying xxx amountAir Ticket
14CDE bought 1 Air Ticket vide PNR - XXXXXXXAir Ticket;PNR
PQ
 
Upvote 0
Hi GraH.. Thanks for your quick responses. I am not so familiar with Power Query, so I prefer going with Option 1.

I didn't quite understand the Name Manager and the formulas'. Where do I paste those formulas ?

Can I keep the key words in a different sheet or file ?

Please advise.

Thanks in advance.

M
 
Upvote 0
Hi, in the final formula replace the arguments vXML and vPosKeyWord by the formulas I've given.
Using the name manager avonds having to repeat long formula Parts amongst others.
You can have your Keywords on another sheet. With PQ in can even be another workbook.
 
Upvote 0
@tinferns
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Since some of your texts contain more than one key word, can you confirm exactly what result you want (eg. first key word, last key word, any key word, all key words)?
 
Upvote 0
@tinferns
Since some of your texts contain more than one key word, can you confirm exactly what result you want (eg. first key word, last key word, any key word, all key words)?
True, the given list may be too short to ensure my formula works in all cases at hand.

So maybe this revisited formula might be better suited:
Book1
ABCDE
1DescriptionResultKey WordsResult
2ABC bought a flight ticket paying XXX amountFlightFlightFlight
3XYZ bought 3 Air Tickets paying xxx amountAir TicketFlightsFlight
4CDE bought 1 Air Ticket vide PNR - XXXXXXXAir TicketTicketAir Ticket
5Air TicketAir Ticket
6Air TicketsAir Ticket
7PNRPNR
8PNR'sPNR
9PNRsPNR
Sheet1
Cell Formulas
RangeFormula
B2:B4B2=INDEX(tKeyWords[Result],AGGREGATE(15,6,(ROW(tKeyWords[Key Words])-ROW(tKeyWords[[#Headers],[Key Words]]))/(ISNUMBER(SEARCH(tKeyWords[Key Words],A2))),1))
 
Upvote 0
Thanks GraH for Option 3 .. I tried the above Index formula in B2 as suggested. Got an error as attached.

As mentioned in my first post, I am okay if excel picks up the first value that matches key values. For eg. in the below example there are 2 key words. Its okay for the formula to pick up the first key word

CDE bought 1 Air Ticket vide PNR - XXXXXXX

Here there are 2 Key words 1) Air Ticket and 2) PNR. Its okay if Excel picks up Air Ticket.

If it's complex to create with a formula (I am guessing it is), I am ok to work with VBA (Macros) if that will make things simple. Please decide and advise.

Thanks,

M
 

Attachments

  • Screenshot 2020-10-04 180616.jpg
    Screenshot 2020-10-04 180616.jpg
    99.5 KB · Views: 18
Upvote 0
Hello tinferns, notice I used a table for your keywords. Select a cell in that range, press CTRL+T and name it tKeyWords. See if that works. I can't help with VBA.
 
Upvote 0
I am okay if excel picks up the first value that matches key values.
Does that imply that it would also be okay to pick up the last one or all of them? If so, here are some formulas that should do that. (I do note that the 'All Key Words' formula results in a duplicate value in row 15 because the text contains 'Ticket' and 'Air Ticket', both of which are key Words.)

BTW, thanks for updating your profile. (y)

20 10 04.xlsm
ABCDE
1Key WordsResult
2FlightFlight
3FlightsFlight
4TicketAir Ticket
5Air TicketAir Ticket
6Air TicketsAir Ticket
7PNRPNR
8PNR'sPNR
9PNRsPNR
10
11
12DescriptionCriteriaLast Key WordAll Key Words
13ABC bought a flight ticket paying XXX amountAir TicketFlight, Air Ticket
14XYZ bought 3 Air Tickets paying xxx amountAir TicketAir Ticket
15CDE bought 1 Air Ticket vide PNR - XXXXXXXPNRAir Ticket, Air Ticket, PNR
Key Words
Cell Formulas
RangeFormula
D13:D15D13=LOOKUP(9.99E+307,SEARCH(" "&$A$2:$A$9&" "," "&A13&" "),$B$2:$B$9)
E13:E15E13=TEXTJOIN(", ",1,IF(ISNUMBER(SEARCH(" "&$A$2:$A$9&" "," "&A13&" ")),B$2:B$9,""))
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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