Line Manager Formula/Macro

ryansm05

Board Regular
Joined
Sep 14, 2016
Messages
148
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need to build a report that can look down a list of line managers and determine the employees that sit under them whether directly or indirectly. For example, the CEO may have 5 direct reports and each of those reports have a further 20 reports.

The formula would need to return the names (or unique employee reference number which may be easier) of the 105 employees that sit under the CEO plus himself. Total would be 106 employees listed by name or employee code.

Similarly, if I picked a manager who had 3 direct reports and these 3 reports were not managers, the formula/macro would finish with these 3 names plus the manager himself. So 4 in total.

I'm restricted by company security on what I can upload online but have provided an example below.

Searching for Steve Fowler and from the RESULT column you can see that ALL employees report into Steve Fowler either directly or indirectly asides from James Windpipe & Jimmy Vialli.

Employee NumberNameLine Manager

<colgroup><col span="3"></colgroup><tbody>
</tbody>
<strike></strike>
RESULT

<colgroup><col></colgroup><tbody>
</tbody>
<strike></strike>
<strike></strike>
1Ryan SmithSteve Fowler
2Jack BrownSteve Fowler
3Tom JudgeSteve Fowler
4Harry WilcoxSteve Fowler
5James WindpipeBobby Henderson
5Michael RooneySteve Fowler
6Harry SherwoodSteve Fowler
7Brad HislopSteve Fowler
8Steve FowlerJose Jepro
9Rio VidicSteve Fowler
10James EastwoodSteve Fowler
11Barry GerrardJames Eastwood
12Nemanja TerryJames Eastwood
13Phil SmallingJames Eastwood
14Alan RashfordJames Eastwood
15Andy IrwinPhil Smalling
16Jimmy Vialli James Windpipe

<colgroup><col span="3"></colgroup><tbody>
</tbody>
<strike></strike>
Ryan Smith
Jack Brown
Tom Judge
Harry Wilcox
Michael Rooney
Harry Sherwood
Brad Hislop
Steve Fowler
Rio Vidic
James Eastwood
Barry Gerrard
Nemanja Terry
Phil Smalling
Alan Rashford
Andy Irwin

<colgroup><col></colgroup><tbody>
</tbody>
<strike></strike>

<tbody>
</tbody>
<strike></strike>

If someone has a formula/macro for this I'd be forever grateful. Happy to assume the range starts at A1.

Thanks in advance
Ryan
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Here's a formula version if suits, I had to use a helper to exclude Bobby & James. If your sheet allows it these columns can be hidden;

We could also look at making a table version so new employees maybe be added;



Book1
ABCDEFGH
1Employee NumberNameLine ManagerRESULTManagerExcludeHelp1Help2
21Ryan SmithSteve FowlerRyan SmithSteve FowlerBobby HendersonSteve FowlerSteve Fowler1
32Jack BrownSteve FowlerJack BrownJames WindpipeSteve FowlerSteve Fowler1
43Tom JudgeSteve FowlerTom JudgeSteve FowlerSteve Fowler1
54Harry WilcoxSteve FowlerHarry WilcoxSteve FowlerSteve Fowler1
65James WindpipeBobby HendersonMichael Rooney
75Michael RooneySteve FowlerHarry SherwoodSteve FowlerSteve Fowler1
86Harry SherwoodSteve FowlerBrad HislopSteve FowlerSteve Fowler1
97Brad HislopSteve FowlerSteve FowlerSteve FowlerSteve Fowler1
108Steve FowlerJose JeproRio VidicSteve FowlerJose Jepro1
119Rio VidicSteve FowlerJames EastwoodSteve FowlerSteve Fowler1
1210James EastwoodSteve FowlerBarry GerrardSteve FowlerSteve Fowler1
1311Barry GerrardJames EastwoodNemanja TerrySteve FowlerJames Eastwood1
1412Nemanja TerryJames EastwoodPhil SmallingSteve FowlerJames Eastwood1
1513Phil SmallingJames EastwoodAlan RashfordSteve FowlerJames Eastwood1
1614Alan RashfordJames EastwoodAndy IrwinSteve FowlerJames Eastwood1
1715Andy IrwinPhil SmallingSteve FowlerPhil Smalling1
1816Jimmy VialliJames Windpipe
Sheet1
Cell Formulas
RangeFormula
G2=IF(OR(C2=$F$2,C2=$F$3),"",$E$2&C2)
H2=IF(ISNUMBER(SEARCH($E$2,G2)),1,"")
D2{=IF(ROWS($D$2:D2)>COUNT(H:H),"",INDEX($B$2:$B$18,SMALL(IF($G$2:$G$18=$E$2&$C$2:$C$18,ROW($A$2:$A$18)-ROW($A$1)),ROWS($D$2:D2))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Thanks for this Ras - I’m not yet at my machine so can only see it on my phone.

I should have mentioned that there may be up to 20,000 employees so a helper sheet would be quite difficult to create. Apologies for not including that in my original post.

Do you think that makes it near impossible?
 
Upvote 0
hmm they are helper columns on the same sheet as your result, although if you have 20k rows and exceptions VBA maybe a better way to go.
 
Upvote 0
Okay no problem - although this formula is still very helpful and I will almost certainly use it for something else. So thank you!


Calling VBA experts ……. any ideas how you can potentially help? :)
 
Upvote 0
Is your goal the same as saying list all employees, except for employees that have Bobby Henderson or James Windpipe as Line managers?
 
Upvote 0

Forum statistics

Threads
1,214,384
Messages
6,119,201
Members
448,874
Latest member
Lancelots

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