Hello,
I am working on consolidating data from a report and I need help finding a faster way to do what I'm doing.
I have a database full of customer numbers - each customer number will appear one or more times in the list. I also have a product code for each line item (which means I could have many product codes for each unique customer number). I'm trying to put together a tab with consolidated information - for example, one column that contains each unique customer number and a corresponding column that contains all of the product codes for the unique customer number.
I already have code that does this, but the original database (the one that contains repeating customer numbers) can contain up to 20,000 line items. Which means, for each unique customer number in the consolidated records, I will have to check each of the 20,000 records for Product code matches. This seems to take much longer than I expected.
Here is the code I have (from the original macro - I have adjusted accordingly for the sample file attached):
For i = 2 To CSFinalRow
PCode = ""
For j = 2 To ODFinalRow
If CS.Cells(i, 3) = OD.Cells(j, 1) Then
If PCode = "" Then
PCode = OD.Cells(j, 11)
Else: PCode = PCode & " " & OD.Cells(j, 11)
End If
End If
CS.Cells(i, 4) = PCode
Next j
Next i
However, there is a lot more to the code than just this piece. So, I have provided a sample file that uses simplified data and code. Please let me know if you can think of a way to speed up the process.
Also, there is one more thing I want to throw out there - sometimes, when I run a macro on my computer that I've also written, it takes a long time for certain things to happen (I don't know why). So, if the macro runs fairly quickly when you test it, then I may not need additional assistance. If this is the case, please just let me know.
Thanks!
Bookmarks