I currently have a sheet in excel with an indented hierarchy of items as shown below.
Each item is indented (four spaces per indent) to show how it fits into the overall hierarchy.
I have been able to create a "Level" column that translates the indentation level into a number.
+------------+-------+--------+
| Item | Level | Parent |
+------------+-------+--------+
| P1 | 1 | N/A |
| P2 | 2 | P1 |
| P3 | 2 | P1 |
| P4 | 3 | P3 |
| P5 | 2 | P1 |
| P6 | 3 | P5 |
+------------+-------+--------+
What I want to do is generate the "Parent" column above, which uses the "level" information to display each item's parent.
I think that this would need to be done with a loop that would do this for each item X :
-Find level info for X
-Find (levelx-1) which would equal the parent item's level
-Search upward for the first row with a level equal to (levelx-1)
-Find the item number in that row
-Write item number in adjacent cell to X
Unfortunately, I'm not sure how to translate this idea into VBA.
Thanks in advance for any assistance.