I have a worksheet that has a sheet of customer invoice data:
Name | Date | OrderID | Item | Price | Email
Anna | 2015-03-10 | ABC123 | Shirt | 5.00 | anna@gmail.com
Bob | 2015-03-11 | ABC124 | Pants | 10.00 | bob@gmail.com
Anna | 2015-03-11 | ABC125 | Pants | 10.00 | anna@gmail.com
Prior, I used a collection by utilizing a for-loop from row 2 to end of the data region, to add to a collection. I created two class modules. One is 'Transaction' and the other 'Invoice'. Within 'Transaction' class module I declared public variables of the components for each transaction, which is Name, Date, OrderID, Item, Price, and Email. The 'Invoice' class module contained procedures which would add each transaction into a collection.
I am starting to look into dictionaries as a way to handle data due to its ability to work with keys. I want the keys to be the Name of the person on the transaction. Because Anna has made two transactions, if I look up the 'Anna' key in the dictionary, I would be able to retrieve the transactions for Anna.
How would I go about doing this? I have been running into errors because the code examples I have been looking at deals with one dimensional data sets.
Sub ProcessData()
Dim dict As Dictionary
Dim i As Integer
Dim TargetRow As Integer
Dim Name As String
Dim Date As Date
Dim OrderID As Double
Dim Item As String
Dim Price As Double
Dim Email As string
Dim More As Boolean
Set dict = New Dictionary
More = True
i = 2
While more
Name = Worksheets("Data").Cells(i, 1).Value
Date = Worksheets("Data").Cells(i, 2).Value
OrderID = Worksheets("Data").Cells(i, 3).Value
Item = Worksheets("Data").Cells(i, 4).Value
Price = Worksheets("Data").Cells(i, 5).Value
Email = Worksheets("Data").Cells(i, 6).Value
dict.Item(Name) = ...
Wend
End Sub