Moving Manager Hierarchy from "LEFT TO RIGHT" to "RIGHT TO LEFT" using vba code

ScotSquad

New Member
Joined
Apr 21, 2017
Messages
6
Hi all,

I have a simplified version of a sheet I'm working with below showing the data as it is, and how I'd like it to be....
CURRENTLY...
Employee
Blank Values in Hierarchy
Line 1 Manager
Line 2 Manager
Line 3 Manager
Line 4 Manager
Employee 1
2
Manager B
Manager A
Employee 2
3
Manager A
Employee 3
1
Manager C
Manager B
Manager A
Employee 4
2
Manager D
Manager A
Employee 5
3
Manager A

<tbody>
</tbody>

HOW I'D LIKE IT TO BE...
Employee
Blank Values in Hierarchy
Line 1 Manager
Line 2 Manager
Line 3 Manager
Line 4 Manager
Employee 1
2
Manager B
Manager A
Employee 2
3
Manager A
Employee 3
1
Manager CManager B
Manager A
Employee 4
2
Manager D
Manager A
Employee 5
3Manager A

<tbody>
</tbody>

Essentially what I'm trying to do is "right-align" the manager hierarchy by moving the hierarchy values to the right depending on the amount of blank values (which I've got a count of for each row in column B). For example, in row 2 (Employee 1) I want to insert 2 cells at C2 to move the hierarchy along by 2. However in row 4 (Employee 3), I'd only want to insert 1 cell at C4 as the data only needs to move along by 1 cell as there is only 1 blank value etc. etc.

Sadly it's not possible to do this manually as I have a sheet with over 1,000 rows so I'm hoping that there is a quick VBA solution that could go through each row by row, checking the value in column B, and inserting the appropriate number of cells at C2, C3, C4 etc. in order to move the data along to "right align" it if that makes sense.

I'd appreciate any help or solution that could be provided, or if anyone can think of a more elegant solution I'd love to hear it!

Thanks in advance!
 
Re: Moving Manager Hierarchy from "LEFT TO RIGHT" to "RIGHT TO LEFT" using vba code - HELP!

I was hoping that it would be possible to insert/shift right cells row-by-row (with the number of cells inserted/shifted based on the value in the "Blank Values in Hierarchy" cell, I can do this manually so I assumed there could be a quick macro/vba script that could do this for the other 999 records!! :)

Thanks

That is what the first code in post #6 does (you obviously haven't tested it) but as it is cutting it also moves any formatting (It could seriously do with having screenupdating turned off though :ROFLMAO:)

Copying and pasting values is the better solution and as gallen has stated the number of columns doesn't affect any of the later codes posted if you have issues with the values then post the actual issues encountered.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Re: Moving Manager Hierarchy from "LEFT TO RIGHT" to "RIGHT TO LEFT" using vba code - HELP!

That is what the first code in post #6 does (you obviously haven't tested it) but as it is cutting it also moves any formatting (It could seriously do with having screenupdating turned off though :ROFLMAO:)

Copying and pasting values is the better solution and as gallen has stated the number of columns doesn't affect any of the later codes posted if you have issues with the values then post the actual issues encountered.

Hi Mark,

Yes, you're right, I was out of the office this morning and so wasn't able to test your solution. I've tried it there and it works a treat, even with the 8 layers of management I have here!

Thanks again for your help with this! Much appreciated! :D
 
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,489
Members
449,166
Latest member
hokjock

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