today, I have been trying to build a hierarchy based on a table like this:
| Item | Cat 1 | Cat 2 | Cat 3 | Quantity |
|---|---|---|---|---|
| 001 | Apple | Fruit | Store 1 | 100 |
| 002 | Orange | Fruit | Store 1 | 100 |
| 003 | Cucumber | Vegetable | Store 1 | 100 |
| 004 | Tomatoe | Vegetable | Store 1 | 100 |
| 005 | Apple | Fruit | Store 2 | 100 |
The hierarchy in Excel should look like this:
| Category | Quantity |
|---|---|
| .... Apple | 100 |
| .... Orange | 100 |
| ..[-] Fruit | 200 |
| .... Cucumber | 100 |
| .... Tomatoe | 100 |
| ..[-] Vegetable | 200 |
| [-] Store 1 | 400 |
| .... Apple | 100 |
| ..[-] Fruit | 100 |
| [-] Store 2 | 100 |
For each category there should be a totals row (below) that also groups the corresponding item rows above (with expand/ collapse).
I started with a simple loop over each row of the control table, that detects when a CAT3/2/1 value has changed and then writes a totals row. However, this turned out to be quite messy after a while.
My second attempt was to create three arrays with distinct categories and looping through these arrays. That worked but took a a long time and seemed inefficient.
I was wondering if anyone has any other ideas?
Sorry for not showing any code. I would like to keep it rather abstract for now.
Thanks in advance!
Gerrit