I am coding a Manager in Excel-VBA with several buttons.
One of them is to generate a tab using another Excel file (let me call it T) as input.
Some properties of T:
~90MBsize~350Klines- Contains sales data of the last
14months (unordered). - Relevant columns:
year/month- total-money
- seller-name
- family-product
- client-name
- There is not id columns (like: cod-client, cod-vendor, etc.)
Main relation:
- Sellers sells many Products to many Clients
I am generating a new Excel tab with data from T of the last year/month grouped by Seller.
Important notes:
Tis the only available input/source.- If two or more Sellers sells the same Product to the same Client, the
total-moneyshould be counted to all of those Sellers.
This is enough, now you know what I have already coded.
My code works, but, it takes about 4 minutes of runtime.
I have already coded some other buttons using smaller sources (not greater than 2MB) which runs in 5 seconds.
Considering T size, 4 minutes runtime could be acceptable.
But I'm not proud of it, at least not yet.
My code is mainly based on Scripting.Dictionary to map data from T, and then I use for each key in obj ... next key to set the grouped data to the new created tab.
I'm not sure, but here are my thoughts:
- If
Nis the total keys in aScripting.Dictionary, and I need to check forobj.Exists(str)before aggregatingtotal-money. It will runNstring compares to returnfalse. - Similarly it will run maximun
Nstring compares when I doSet seller = obj(seller_name).
I want to be wrong with my thoughts. But if I'm not wrong, my next step (and last hope) to reduce the runtime of this function is to code my own class object with Tries.
I will only start coding tomorrow, what I want is just some confirmation if I am in the right way, or some advices if I am in the wrong way of doing it.
Do you have any suggestions? Thanks in advance.
Dictionaryfor that can't be accomplished by an array? If your concern is performance, arrays are hard to beat unless you need some feature like key look-up..existsand.remove. Basically i always use dictionary, unless there are not unique keys, or i work on small range.