Excel Macro to split sheets by managers direct/indirect employees

tpadd8

New Member
Joined
Nov 15, 2022
Messages
1
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am attempting to write a macro in Excel that is a bit complex (at least for me) to assist at work. I have a list of employees and their salary ranges and I want to be able to break the sheet up by managers and their direct/indirect reports. For example: John Smith is the VP and has 5 direct reports, I want the macro to grab the 5 ranges of those direct reports, but also the ranges of the direct reports (if any) of those 5 people. So John Smith would receive the salary ranges of all the people in this example, but Sam Jones would only receive his 2 direct reports and the 3 direct reports of Jane Doe as she is a direct report of Sam. Hopefully that somewhat makes sense! It can also delete any duplicate ranges (if career level, grade, zone, structure are the same for more than one person). One more, if it could please save the file under the name of the manager - thank you!
 

Attachments

  • Data.png
    Data.png
    24.5 KB · Views: 21
  • Jane Doe Output.png
    Jane Doe Output.png
    9.1 KB · Views: 22
  • John Smith Output.png
    John Smith Output.png
    13.2 KB · Views: 16
  • Sam Jones Output.png
    Sam Jones Output.png
    11 KB · Views: 21

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
How about just pulling the main Data table and splitting it up from there. Clean it up as needed and sort by Manager, then create copies of it for each Manager referencing that table, filter for one manager and then load those tables.

Data
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", Int64.Type}, {"Employee", Int64.Type}, {"Employee Name", type text}, {"W", type text}, {"Manager Name", type text}, {"Manager", Int64.Type}, {"# of Direct", Int64.Type}, {"# of Indirect Career Level Grade", Int64.Type}, {"Column1", type text}, {"Column2", Int64.Type}, {"Zone", type text}, {"Structure", type text}, {"202.3 Min", Int64.Type}, {"2023 MRP", Int64.Type}, {"2023 Max", Int64.Type}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","Doe, Ja ne","Doe, Jane",Replacer.ReplaceText,{"Manager Name"}),
    #"Sorted Rows" = Table.Sort(#"Replaced Value",{{"Manager Name", Order.Ascending}})
in
    #"Sorted Rows"

JaneDoe
Power Query:
let
    Source = Data,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Manager Name] = "Doe, Jane"))
in
    #"Filtered Rows"

SamJones
Power Query:
let
    Source = Data,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Manager Name] = "Jones, Sam"))
in
    #"Filtered Rows"

Book1
ABCDEFGHIJKLMNO
1Data
2LocationEmployeeEmployee NameWManager NameManager# of Direct# of Indirect Career Level GradeColumn1Column2ZoneStructure202.3 Min2023 MRP2023 Max
390350Test, TestSmith, JohnDoe, Ja ne356Sl1Zone3A$1.00$11.00$21.00
490351None, NoneSmith, JohnDoe, Jane356Sl1Zone4A$2.00$12.00522
590352Person, PersonSmith, JohnSmith, John440S22Zone7A$3.00$13.00$23.00
690353Human, HumanSm ith, JohnSm ith, John4406M26Zone7A$4.00$14.00$24.00
790354Page, CedricSm ith, JohnJones, Sam356B25Zone7A$5.00$15.00$25.00
890355Employee, EmployeeSmith, JohnSm ith, John4401M.26Zone7A$6.00$16.00526
990356Doe, JaneSm ith, JohnJones, Sam3593Ml5Zone7A$7.00$17.00$27.00
1090357Worker, WorkerSmith, JohnSmith, John440M26Zone7A$8.00$18.00$28.00
1190358Nobody, NobodySmith, JohnDoe, Ja ne356Sl1ZonesA$9.00$19.00$29.00
1290359Jones, SamSm ith, JohnSmith, John44023M.26Zone7A$10.00$20.00$30.00
13
14JaneDoe
15LocationEmployeeEmployee NameWManager NameManager# of Direct# of Indirect Career Level GradeColumn1Column2ZoneStructure202.3 Min2023 MRP2023 Max
1690358Nobody, NobodySmith, JohnDoe, Jane356Sl1ZonesA91929
1790351None, NoneSmith, JohnDoe, Jane356Sl1Zone4A212522
1890350Test, TestSmith, JohnDoe, Jane356Sl1Zone3A11121
19
20SamJones
21LocationEmployeeEmployee NameWManager NameManager# of Direct# of Indirect Career Level GradeColumn1Column2ZoneStructure202.3 Min2023 MRP2023 Max
2290356Doe, JaneSm ith, JohnJones, Sam3593Ml5Zone7A71727
2390354Page, CedricSm ith, JohnJones, Sam356B25Zone7A51525
Sheet1


The name above each Query and Table is their name. NOTE: Do NOT put the resulting tables ( JaneDoe, SamJones ) or ANYTHING under the Data Table. Best to put each in their own Worksheet. Now, as the Data Table grows, a simple Refresh All will update the appropriate tables. No VB code required.

Pretty nifty, eh? BTW, please use XL2BB. I used Power Query to import the Data Table from a Screenshot, and assume the correction I did in that table was caused by that, but I let it go to show that you can fix the data in the Data Table and those fixes will flow to the subsequent tables.
 
Upvote 0

Forum statistics

Threads
1,224,759
Messages
6,180,814
Members
452,996
Latest member
nelsonsix66

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