I have a list of products each of which has its own keywords that can be used to search for that product on the site. I want to generate a list of unique keywords and a list of products that can be found for each unique keyword.
Source example
Products Keywords
-------- --------
Envelope1 1,envelope
Envelope2 2,envelope
Label1 label,mailing
label2 label,mailing
label3 label,mailing,address
The generated list that I want would look like...
Keywords Products
-------- --------
1 Envelope1
2 Envelope2
envelope Envelope1,Envelope2
label label1,label2,label3
mailing label1,label2,label3
address label3
I would then loop through the keywords and fetch the products for that keyword, execute a search, and then validate that all the products were found.
I can create a collection that contains the unique list of keywords but I'm struggling on how to create the associated list of products. I think I want to use a nested collection as is described here but I'm having a hard time figuring out the details because I'm trying to add to a dynamic list.
' loop through each cell in the keywords column, ignoring the column header
For i = 2 To maxRow
' the keywords are comma delimited so they must be Split()
k = Split(ActiveSheet.Cells(i, keywordColumn).Value, ",")
For j = 0 To UBound(k)
' turn off error checking to trap Error 457
On Error Resume Next
keywords.Add Item:=k(j), Key:=k(j)
errNumber = CLng(Err.Number)
On Error GoTo 0
' trap Error 457, the key already exists in the collection
' then ... do something to associate the product with the keyword
If errNumber = 457 Then
keywords.Item(k(j)).Add productCode???
End If
Next j
Next i
I'm not tied to this method so if there's a better way to do this... I'm fine with that. Thanks in advance for the help.