Parent Child Hierarchy

mikeyosyd

New Member
Joined
Apr 18, 2018
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi wonderful people. I'm hoping you may be able to help. Apologies if this has already been solved elsewhere.

I have HR data like the inout data table below where I have manager and subordinate employee numbers.

I'd like to find some VBA code to output the table to the right below. In my case of the HR hierarchy data this enables me to pick any manager and find all the subordinates to them down through the full organisational tree.


[TABLE="width: 435"]
<colgroup><col width="87" span="5" style="width: 65pt;"></colgroup><tbody>[TR]
[TD="class: xl65, width: 87"]Input Data[/TD]
[TD="width: 87"][/TD]
[TD="width: 87"][/TD]
[TD="width: 87"]Output Data[/TD]
[TD="width: 87"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="class: xl66, align: center"]Parent[/TD]
[TD="class: xl66, align: center"]Child[/TD]
[TD][/TD]
[TD="class: xl66, align: center"]Parent [/TD]
[TD="class: xl66, align: center"]Children[/TD]
[/TR]
[TR]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]B[/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]B[/TD]
[/TR]
[TR]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]C[/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]C[/TD]
[/TR]
[TR]
[TD="class: xl65, width: 87"]C[/TD]
[TD="class: xl65, width: 87"]D[/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]D[/TD]
[/TR]
[TR]
[TD="class: xl65, width: 87"]C[/TD]
[TD="class: xl65, width: 87"]E[/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]E[/TD]
[/TR]
[TR]
[TD="class: xl65, width: 87"]D[/TD]
[TD="class: xl65, width: 87"]G[/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]G[/TD]
[/TR]
[TR]
[TD="class: xl65, width: 87"]G[/TD]
[TD="class: xl65, width: 87"]H[/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]A[/TD]
[TD="class: xl65, width: 87"]H[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]C[/TD]
[TD="class: xl65, width: 87"]D[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]C[/TD]
[TD="class: xl65, width: 87"]E[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]C[/TD]
[TD="class: xl65, width: 87"]G[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]C[/TD]
[TD="class: xl65, width: 87"]H[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]D[/TD]
[TD="class: xl65, width: 87"]G[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]D[/TD]
[TD="class: xl65, width: 87"]H[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="class: xl65, width: 87"]G[/TD]
[TD="class: xl65, width: 87"]H[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
See this code provided by pgc01 in another thread
https://www.mrexcel.com/forum/excel...-children-parent-post3892723.html#post3892723

Hope this helps

M.


Hi, thanks so much thats extremely promising. I got an error when I ran it on my dataset of "out of stack space". If you had any thoughts on how to resolve I'd be very grateful. As a guide, my dataset has around 7000 parent-child relationships on the input table. I'll post the same question back to the other thred.

Thanks
 
Upvote 0
I do not know if there is any limitation in Excel for recursive codes. I hope the code author can help you.

M.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top