Adding Category column based on Item and Product columns

Himaja

Board Regular
Joined
Oct 14, 2013
Messages
62
Hi,

Say, I have below table (originally 10000+ rows) where I need to assign category number based on Item, Product columns and also below conditions. Can someone please help me on this

Each product has multiple items and each item has multiple products

Conditions:
Rows with same product number should be under same category number. Cannot break product into multiple categories
Similar item rows are also to be under same category ie., partial Items ("Item" Column) in a category are as minimal as possible
Ideal number of rows in each category should be <=150


ItemProductCategory (To be filled)
Item 1Product 1Cat 1
Item 2Product 1Cat 1
Item 3Product 1Cat 1
Item 1Product 2Cat 1
Item 1Product 3Cat 1
Item 5Product 1Cat 1
Item 4Product 4Cat 2
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try:
sample zipcode file.xlsx
ABC
1temProductCategory (To be filled)
2Item 1Product 1Cat 1
3Item 2Product 1Cat 1
4Item 3Product 1Cat 1
5Item 1Product 2Cat 1
6Item 1Product 3Cat 1
7Item 5Product 1Cat 1
8Item 4Product 4Cat 2
Sheet2
Cell Formulas
RangeFormula
C2:C8C2=IF(COUNTIF($A$1:A1,A2)=0,IF(COUNTIF($B$1:B1,B2)=0,"Cat "&SUMPRODUCT(1/COUNTIF($C$1:C1,$C$1:C1)),VLOOKUP(B2,$B$1:$C1,2,0)),VLOOKUP(A2,$A$1:$C1,3,0))
 
Upvote 0
Try:
sample zipcode file.xlsx
ABC
1temProductCategory (To be filled)
2Item 1Product 1Cat 1
3Item 2Product 1Cat 1
4Item 3Product 1Cat 1
5Item 1Product 2Cat 1
6Item 1Product 3Cat 1
7Item 5Product 1Cat 1
8Item 4Product 4Cat 2
Sheet2
Cell Formulas
RangeFormula
C2:C8C2=IF(COUNTIF($A$1:A1,A2)=0,IF(COUNTIF($B$1:B1,B2)=0,"Cat "&SUMPRODUCT(1/COUNTIF($C$1:C1,$C$1:C1)),VLOOKUP(B2,$B$1:$C1,2,0)),VLOOKUP(A2,$A$1:$C1,3,0))
Thanks a lot for your solution. Kudos to you. You did solve my first 2 conditions but the last condition of number of rows in a category > 150. Also one other request. Can you please explain me the formula on how it works? This would really help me in understanding how you put together formulas nicely and will also help me for my learning. Thanks in Advance.
 
Upvote 0
Thanks a lot for your solution. Kudos to you. You did solve my first 2 conditions but the last condition of number of rows in a category > 150. Also one other request. Can you please explain me the formula on how it works? This would really help me in understanding how you put together formulas nicely and will also help me for my learning. Thanks in Advance.
Sorry bebo021999, the formula that you gave did not work for products. I'm getting multiple same Product rows part of different groups.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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