I have some exported files to work with, collating and summing data for individual SKUs.
A PaymentType file has details of the type of payment(s) made for each order number. Most order numbers have just one payment. The odd one has multiple payments applied to the one order.
Another file has the OrderDetails (SKUs and prices) that constitute those orders. For those orders with just one payment, it's simple to sum the SKUs, however, for the orders that have multiple payments applied, the OrderDetails file records multiple instances of the SKUs (on a new line). If I sold one Apple in an order with one payment, then only one Apple shows in the OrderDetails file, but if three part-payments were made for an order for one Orange, then the OrderDetails file shows three records for one Orange, with the same order number.
i.e.
The only way I know how to accomplish correcting the summed data is as follows:
Use Application.WorksheetFunction.CountIF to examine the PaymentType file for duplicates and create a temporary table with the order number and number of payments.
Step through each line of the OrderDetails file and use Application.WorksheetFunction.VLookup to check each order number against the temporary table and then divide the values in the SKU column by the number of instances in the temporary table. This would mean, in the example above, I would get 1 Apple/1 occurance = 1 Apple; and each of the three lines for Orange would be changed to 1/3 Orange, so the final sum (with later code) would be 3 * 1/3 = 1 Orange.
Is there a more efficient way for me to achieve the same result?
A PaymentType file has details of the type of payment(s) made for each order number. Most order numbers have just one payment. The odd one has multiple payments applied to the one order.
Another file has the OrderDetails (SKUs and prices) that constitute those orders. For those orders with just one payment, it's simple to sum the SKUs, however, for the orders that have multiple payments applied, the OrderDetails file records multiple instances of the SKUs (on a new line). If I sold one Apple in an order with one payment, then only one Apple shows in the OrderDetails file, but if three part-payments were made for an order for one Orange, then the OrderDetails file shows three records for one Orange, with the same order number.
i.e.
Order | SKU | Quantity |
#1135 | Apple | 1 |
#1136 | Orange | 1 |
#1136 | Orange | 1 |
#1136 | Orange | 1 |
The only way I know how to accomplish correcting the summed data is as follows:
Use Application.WorksheetFunction.CountIF to examine the PaymentType file for duplicates and create a temporary table with the order number and number of payments.
Step through each line of the OrderDetails file and use Application.WorksheetFunction.VLookup to check each order number against the temporary table and then divide the values in the SKU column by the number of instances in the temporary table. This would mean, in the example above, I would get 1 Apple/1 occurance = 1 Apple; and each of the three lines for Orange would be changed to 1/3 Orange, so the final sum (with later code) would be 3 * 1/3 = 1 Orange.
Is there a more efficient way for me to achieve the same result?