Categorise according to key words in item description

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
165
Office Version
  1. 365
Platform
  1. Windows
Hi all, I would like to automatically populate a cell based on key words in the item description. The item description would read something like Electricity HR or Fees Marketing. I have a list on the spreadsheet listing the various cost centres such as HR, Marketing etc. So the formula needs to scan the cell containing the item description and then search for one of the cost centres. It then populates a cell with HR etc. The list of cost centres can change so it would be preferable if the formula was range-based or was capable of adjusting to the various cost centres.
I hope this makes sense, I have downloaded the XL2BB add-in but I don't seem to have full functionality so I can't illustrate by way of an example.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Got the functionality now, what needs to happen now is that the Column headed Category would show HR in C2, C3 would list Finance etc.


ItemAmountCategory
Electricity HR$20List
Water Finance$50HR
Electricity Finance$35Finance
Staff expenses HR$40Marketing
Water Marketing$60
 
Upvote 0
Book1
ABCDE
1ItemAmountCategory
2Electricity HR20HRList
3Water Finance50FinanceHR
4Electricity Finance35FinanceFinance
5Staff expenses HR40HRMarketing
6Water Marketing60Marketing
Sheet2
Cell Formulas
RangeFormula
C2:C6C2=INDEX(Table3[List],SUMPRODUCT(ISNUMBER(SEARCH(Table3[List],A2))*ROW($1:$3)))
 
Upvote 0
@StuLux
I don't know exactly what is possible with the OP's data but that formula would fail for an item like "Highrise Marketing"

@tigerzen
Welcome to the MrExcel board!

You could try this.

23 03 08.xlsm
ACDE
1ItemCategory
2Electricity HRHRList
3Water FinanceFinanceHR
4Electricity FinanceFinanceFinance
5Staff expenses HRHRMarketing
6Water MarketingMarketing
7Highrise MarketingMarketing
8HR MarketingHR, Marketing
9Electricity Workshopunknown
Category
Cell Formulas
RangeFormula
C2:C9C2=TEXTJOIN(", ",,FILTER(E$3:E$5,ISNUMBER(SEARCH(" "&E$3:E$5&" "," "&A2&" ")),"unknown"))


Note that if it is not possible to have multiple categories within a single item like row 8 in my sample then the formula could be simplified to

Excel Formula:
=FILTER(E$3:E$5,ISNUMBER(SEARCH(" "&E$3:E$5&" "," "&A2&" ")),"unknown")
 
Upvote 1
Solution
Thanks so much for the replies Stu and Peter. Both work fine but Peter you are correct with the Highrise entry, very good pickup! Also, love the brevity of your functions, this makes it easier for me to recreate when needed. Still have to get my head around the Filter function but it appears to be a very powerful feature.
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)

Both work fine
Just so long as you are aware that one looks for "words" in the Item whereas the other looks for "strings" in the Item. So particularly any short "string" in the List column (like HR) could possibly turn up within a longer "word" in an Item description and therefore give you a false result or an error.
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)


Just so long as you are aware that one looks for "words" in the Item whereas the other looks for "strings" in the Item. So particularly any short "string" in the List column (like HR) could possibly turn up within a longer "word" in an Item description and therefore give you a false result or an error.
Thank you for pointing that out, very useful to know.
 
Upvote 0
@StuLux
I don't know exactly what is possible with the OP's data but that formula would fail for an item like "Highrise Marketing"

@tigerzen
Welcome to the MrExcel board!

You could try this.

23 03 08.xlsm
ACDE
1ItemCategory
2Electricity HRHRList
3Water FinanceFinanceHR
4Electricity FinanceFinanceFinance
5Staff expenses HRHRMarketing
6Water MarketingMarketing
7Highrise MarketingMarketing
8HR MarketingHR, Marketing
9Electricity Workshopunknown
Category
Cell Formulas
RangeFormula
C2:C9C2=TEXTJOIN(", ",,FILTER(E$3:E$5,ISNUMBER(SEARCH(" "&E$3:E$5&" "," "&A2&" ")),"unknown"))


Note that if it is not possible to have multiple categories within a single item like row 8 in my sample then the formula could be simplified to

Excel Formula:
=FILTER(E$3:E$5,ISNUMBER(SEARCH(" "&E$3:E$5&" "," "&A2&" ")),"unknown")
I've been using the second formula but there is a slight problem if you use dynamic range names. The formula returns #SPILL because there will be blank cells in the range name. Is there a way to circumvent this besides using CTRL SHIFT ENTER? I am setting this up for an inexperienced EXCEL user and don't want to complicate things too much. Interestingly if you use the first formula with TEXTJOIN you do not get a SPILL error. I tend to use dynamic range names a bit so am wondering how we get around the blank cells in the range name.
 
Upvote 0
Perhaps you could be a bit more specific and give some concrete (but dummy) examples of your data and expected results and details of your 'dynamic range name' & how it is defined?
It would also help if you could clarify whether it is possible that two (or more) values from your 'List' could occur in an item name - like my example in row 8 of post #4.
If that is possible, then clarification of exactly what result(s) you would want would also be helpful.
 
Upvote 0
Perhaps you could be a bit more specific and give some concrete (but dummy) examples of your data and expected results and details of your 'dynamic range name' & how it is defined?
It would also help if you could clarify whether it is possible that two (or more) values from your 'List' could occur in an item name - like my example in row 8 of post #4.
If that is possible, then clarification of exactly what result(s) you would want would also be helpful.
Sure, no problems. Below is what I get, having been through the data it is most unlikely that 2 or more list values can occur simultaneously.
As can be seen from this example I receive a Spill error but the correct answer is produced if Ctrl+Shift+Enter is used on the formula.
List formula is =OFFSET(Sheet1!$E$3,0,0,COUNTA(Sheet1!$E:$E),1)
ItemAmountCategory
Electricity HR$20#SPILL!List
Finance$50#SPILL!HR
Electricity Finance$35#SPILL!Finance
Staff expenses HR$40#SPILL!Marketing
Water Marketing$60Marketing
0
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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