I have a table, which contains employee assignments: Each column header is the names of their supervisor; the rows underneath are the names of the employees assigned to that person.
For example, my table is approx. 12 columns wide, one column for each supervisor. Approx. 14 rows, each containing the name of an employee assigned to that supervisor.
I need to transpose this information into a second table: This table is only two columns wide: Column A contains a list of ALL the employees, and Column B contains the name of their assigned supervisor.
Presently my code works, however my concern is with copying and pasting the column headers from the first table into the second table. The only way I've been getting it to work, is to use a predefined range based on the number of rows in the first table. This can be tedious to edit if we add/remove supervisors.
My question is, can I avoid the need to use a "predefined range" for copying/pasting the table headers? Is there a way I can paste into the new table (column B) based on a row in column A?
- So for instance, if an employee in column A works for Supervisor "John Smith" (and is listed under his column in the first table; worksheets("Quality Assignments") Table 2), I want to paste the header "John Smith" in the column next to his employee. Any help/advice is greatly appreciated.
Here is my code:
' This is where J. Smith begins
Worksheets("Employee Assignments").Range("Table2[John Smith]").Copy
With Worksheets("Supervisor Listing").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
Worksheets("Employee Assignments").Range("Table2[[#Headers],[John Smith]]").Copy
Worksheets("Supervisor Listing").Select
Range("B4:B17").Select
ActiveSheet.Paste
' This is where J. Doe begins
Worksheets("Employee Assignments").Range("Table2[Jane Doe]").Copy
With Worksheets("Supervisor Listing").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
Worksheets("Employee Assignments").Range("Table2[[#Headers],[Jane Doe]]").Copy
Worksheets("Supervisor Listing").Select
Range("B18:B31").Select
ActiveSheet.Paste