Forum

Categories distribu...
 
Notifications
Clear all

Categories distribution

5 Posts
3 Users
0 Reactions
52 Views
(@bill-jone)
Posts: 28
Eminent Member
Topic starter
 

Hi,

Please can you help me to distribute the Categories on Product lines as below.

Input:

Sheet1: Column A " Part Number", Column B"Product Line"

Sheet2: Column A " Product Line ", Column B"Category".

Output:

Sheet1: Column C

Please check attached file to get sample.

Thanks;

Bill

 
Posted : 30/07/2019 7:14 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Bill,

No file attached.

regards

Phil

 
Posted : 30/07/2019 9:37 pm
(@bill-jone)
Posts: 28
Eminent Member
Topic starter
 

Please check.

 

Thanks;

Bill

 
Posted : 31/07/2019 7:47 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Bill,

Here is a code you can try:

Sub GetCategory()
Dim Dict As Object: Set Dict = CreateObject("scripting.dictionary")
Dim i As Long, CategString As String, ItemsList As Variant, Itm As Variant
With ThisWorkbook.Worksheets("Product Line & Category")
i = 2
'load categories to dictionary
Do
Dict(.Cells(i, "A").Value) = .Cells(i, "B").Value
i = i + 1
Loop Until Len(.Cells(i, "A")) = 0
End With

With ThisWorkbook.Worksheets("Parts")
i = 2
Do
CategString = ""
ItemsList = Split(.Cells(i, "B").Value, "|")
For Each Itm In ItemsList
If Dict.Exists(CStr(Itm)) Then
If InStr(1, CategString, Dict(CStr(Itm)), vbTextCompare) = 0 Then CategString = CategString & "|" & Dict(CStr(Itm))
End If
Next Itm
If CategString Like "|*" Then CategString = Right(CategString, Len(CategString) - 1)
.Cells(i, "C").Value = CategString
i = i + 1
Loop Until Len(.Cells(i, "A")) = 0
End With

End Sub

 
Posted : 06/08/2019 7:06 am
(@bill-jone)
Posts: 28
Eminent Member
Topic starter
 

Thank you very much; your support is greatly appreciated.

 

Thanks;

Bill

 
Posted : 23/08/2019 6:21 am
Share: