Let's call the numbering system in column 1 a work breakdown structure (WBS) or hierarchical taxonomy.
I am attempting to calculate item and sub-item 'Amount' totals. Each higher WBS level is always the sum of the elements from the next lower tier only. Each total is a 'rolled up' amount from the levels below it, which are in turn rolled up from levels below, etc.
The dollar amount for any top level 'Thing n' (1) is the sum of values for all items in the hierarchical level below that level (1 = 1.1 + 1.3), which is in turn sum of values for all items in the next hierarchical level below that level (1.1 = 1.1.1 + 1.1.3 + 1.1.5 + 1.1.7), and so on.
For any parent element with children below it, the parent amount must equal the sum of its children, and so on back up the tree.
I believe a VBA function is the likeliest solution, though the actual code is beyond my skill level. Thanks in advance for any assistance.
Brian
[TABLE="width: 279"]
<tbody>[TR]
[TD="class: xl66, width: 70, bgcolor: #4F81BD"]Number[/TD]
[TD="width: 114, bgcolor: #4F81BD"]Description[/TD]
[TD="class: xl65, width: 95, bgcolor: #4F81BD"] Amount[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #DCE6F1"]1[/TD]
[TD="class: xl71, bgcolor: #DCE6F1"] Thing 1[/TD]
[TD="class: xl71, bgcolor: #DCE6F1"] $ 56.25[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1[/TD]
[TD="class: xl72"]Sub 1a[/TD]
[TD="class: xl73"] $ 36.25[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.1.1[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 2.25[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1.3[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 15.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.1.3.1[/TD]
[TD="class: xl74, bgcolor: #DCE6F1"]Sub-Sub-Sub[/TD]
[TD="class: xl70, bgcolor: #DCE6F1"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1.3.3[/TD]
[TD="class: xl74"]Sub-Sub-Sub[/TD]
[TD="class: xl70"] $ 5.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.1.5[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 2.50[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1.7[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 1.50[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.3[/TD]
[TD="class: xl72, bgcolor: #DCE6F1"]Sub 1b[/TD]
[TD="class: xl73, bgcolor: #DCE6F1"] $ 20.00[/TD]
[/TR]
[TR]
[TD="class: xl71"] 2[/TD]
[TD="class: xl71"] Thing 2[/TD]
[TD="class: xl71"] $ 65.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.1[/TD]
[TD="class: xl72, bgcolor: #DCE6F1"]Sub 2a[/TD]
[TD="class: xl73, bgcolor: #DCE6F1"] $ 40.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]2.1.1[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.1.3[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]2.1.5[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.1.7[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]2.3[/TD]
[TD="class: xl72"]Sub 2b[/TD]
[TD="class: xl73"] $ 25.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.3.1[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 25.00[/TD]
[/TR]
</tbody>[/TABLE]
- There is no fixed number of elements below a top level,
- There is no fixed number of sub-indents.
- Therefore, the maximum length of 'Number' field is variable and unknown.
I am attempting to calculate item and sub-item 'Amount' totals. Each higher WBS level is always the sum of the elements from the next lower tier only. Each total is a 'rolled up' amount from the levels below it, which are in turn rolled up from levels below, etc.
The dollar amount for any top level 'Thing n' (1) is the sum of values for all items in the hierarchical level below that level (1 = 1.1 + 1.3), which is in turn sum of values for all items in the next hierarchical level below that level (1.1 = 1.1.1 + 1.1.3 + 1.1.5 + 1.1.7), and so on.
For any parent element with children below it, the parent amount must equal the sum of its children, and so on back up the tree.
I believe a VBA function is the likeliest solution, though the actual code is beyond my skill level. Thanks in advance for any assistance.
Brian
[TABLE="width: 279"]
<tbody>[TR]
[TD="class: xl66, width: 70, bgcolor: #4F81BD"]Number[/TD]
[TD="width: 114, bgcolor: #4F81BD"]Description[/TD]
[TD="class: xl65, width: 95, bgcolor: #4F81BD"] Amount[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #DCE6F1"]1[/TD]
[TD="class: xl71, bgcolor: #DCE6F1"] Thing 1[/TD]
[TD="class: xl71, bgcolor: #DCE6F1"] $ 56.25[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1[/TD]
[TD="class: xl72"]Sub 1a[/TD]
[TD="class: xl73"] $ 36.25[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.1.1[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 2.25[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1.3[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 15.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.1.3.1[/TD]
[TD="class: xl74, bgcolor: #DCE6F1"]Sub-Sub-Sub[/TD]
[TD="class: xl70, bgcolor: #DCE6F1"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1.3.3[/TD]
[TD="class: xl74"]Sub-Sub-Sub[/TD]
[TD="class: xl70"] $ 5.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.1.5[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 2.50[/TD]
[/TR]
[TR]
[TD="class: xl66"]1.1.7[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 1.50[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]1.3[/TD]
[TD="class: xl72, bgcolor: #DCE6F1"]Sub 1b[/TD]
[TD="class: xl73, bgcolor: #DCE6F1"] $ 20.00[/TD]
[/TR]
[TR]
[TD="class: xl71"] 2[/TD]
[TD="class: xl71"] Thing 2[/TD]
[TD="class: xl71"] $ 65.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.1[/TD]
[TD="class: xl72, bgcolor: #DCE6F1"]Sub 2a[/TD]
[TD="class: xl73, bgcolor: #DCE6F1"] $ 40.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]2.1.1[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.1.3[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]2.1.5[/TD]
[TD="class: xl69"]Sub-Sub[/TD]
[TD="class: xl65"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.1.7[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub-Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 10.00[/TD]
[/TR]
[TR]
[TD="class: xl66"]2.3[/TD]
[TD="class: xl72"]Sub 2b[/TD]
[TD="class: xl73"] $ 25.00[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: #DCE6F1"]2.3.1[/TD]
[TD="class: xl69, bgcolor: #DCE6F1"]Sub[/TD]
[TD="class: xl65, bgcolor: #DCE6F1"] $ 25.00[/TD]
[/TR]
</tbody>[/TABLE]
Last edited: