I need to fill a Products table in file A with their manufacturing costs that are in another Costs table in file B.

Currently, I read Products and Costs tables into their respective arrays and for each product I iterate over each cost looking for the right one. Basically, VLOOKUP done with arrays.

Isn't it O(n^2)? I feel like there should be a better way to do this. Should I use ADO? Dictionary with key as a lookup value?

  • It is not clear what you are trying to do. – ctrl-alt-delor Jun 18 '18 at 18:33

Short answer: use a dictionary. That will typically be cleaner and faster than anything else. Note, in VBA, you cannot directly put records of a user defined type into a dictionary, but if your Costs are just numbers, indexed by some product id, this is not a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.