Inserting values from only certain columns to rows

CKings

New Member
Joined
Jan 4, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,
I'm helping a friend out with her Excel issue and I don't have the answer either. Maybe someone else has an idea. We have an employee data file where employees are allocated to different legal entities. We are doing an analysis on FTE and for this, we need to insert allocations listed in columns into rows in order to complete our analysis. A pivot wouldn't work regarding other analysis we have to do.

The spreadsheet is as follow:
Row 1: column titles
Row 2: data as presented in the extract we have to work in. Here you see that "Cost FTE" is 1 and .5 of this is allocated to Company A and .5 to Company B.
Row 3+4: this is how we would like to bring in the data ideally: each allocation into a new row without adding the first name more than once. Row 2 can be deleted. Biggest issue is that the number of allocations can differ. Sometimes it's just one company, sometimes up to 8.

Would there be a solution? Currently, this is a manual and error-prone process.

Thank you!

Legal entity – allocatedEmployee numberFirst nameLast nameCost FTECategoryJob FamilyLegal entity – allocated (1)Allocation % (1)Legal entity – allocated (2)Allocation % (2)Legal entity – allocated (3)Allocation % (3)
Company AABC123JohnDoe
1​
EmployeeSalesCompany A
0.5​
Company B
0.5​
Company AABC123JohnDoe
0.5​
EmployeeSales
Company BABC1230Doe
0.5​
EmployeeSales
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to MrExcel Message Board. Please upload your Example file & Also Desired Result at Different Sheet with XL2BB ADDIN (Preferable) Or upload at Free Hosting site e.g. www.dropbox.com or google drive or OneDrive and Insert Link here.
 
Upvote 0
Information to add:
The current spreadsheet is as follow:

Legal entity – allocatedEmployee numberFirst nameLast nameCost FTECategoryJob FamilyLegal entity – allocated (1)Allocation % (1)Legal entity – allocated (2)Allocation % (2)Legal entity – allocated (3)Allocation % (3)Legal entity – allocated (4)Allocation % (4)Legal entity – allocated (5)Allocation % (5)Legal entity – allocated (6)Allocation % (6)Legal entity – allocated (7)Allocation % (7)Legal entity – allocated (8)
Company AABC123JohnDoe1EmployeeSalesCompany A0.5Company B0.5
Company AABC124JaneSmith1EmployeeFinanceCompany A0.5Company B0.2Company C0.3
Company BABC125KenBlack1EmployeeSalesCompany B0.8Company C0.2


And this is how it should look like:

Legal entity – allocatedEmployee numberFirst nameLast nameCost FTECategoryJob FamilyLegal entity – allocated (1)Allocation % (1)
Company AABC123JohnDoe0.5EmployeeSales
Company BABC123JohnDoe0.5EmployeeSales
Company AABC124JaneSmith0.5EmployeeFinance
Company BABC124JaneSmith0.2EmployeeFinance
Company CABC124JaneSmith0.3EmployeeFinance
Company BABC125KenBlack0.8EmployeeSales
Company CABC125KenBlack0.2EmployeeSales
 
Upvote 0
Try this:
I suppose your Data start at Cell A1 at Sheet1. You can See Result at Sheet2
VBA Code:
Sub ArrangeData()
Dim Lr As Long, Lr2 As Long, i As Long, j As Long, Ws As Worksheet, Ws2 As Worksheet, a As Long, Lc As Long
Dim b As Long, c As Long, d As Long
Set Ws = Sheets("Sheet1")
Set Ws2 = Sheets("Sheet2")

Lr = Ws.Cells(Rows.Count, 1).End(xlUp).Row
d = 0

For i = 2 To Lr
Lc = Ws.Cells(i, Columns.Count).End(xlToLeft).Column
b = (Lc - 7) / 2
For j = 1 To 7
Ws2.Cells(1, j).Value = Ws.Cells(1, j).Value
For c = 1 To b
If j = 1 Then
Ws2.Cells(d + c + 1, j).Value = Ws.Cells(i, 6 + 2 * c).Value
ElseIf j = 5 Then
Ws2.Cells(d + c + 1, j).Value = Ws.Cells(i, 7 + 2 * c).Value
Else
Ws2.Cells(d + c + 1, j).Value = Ws.Cells(i, j).Value
End If
Next c
Next j
d = d + b
Next i

End Sub
 
Upvote 0
Try this:
I suppose your Data start at Cell A1 at Sheet1. You can See Result at Sheet2
VBA Code:
Sub ArrangeData()
Dim Lr As Long, Lr2 As Long, i As Long, j As Long, Ws As Worksheet, Ws2 As Worksheet, a As Long, Lc As Long
Dim b As Long, c As Long, d As Long
Set Ws = Sheets("Sheet1")
Set Ws2 = Sheets("Sheet2")

Lr = Ws.Cells(Rows.Count, 1).End(xlUp).Row
d = 0

For i = 2 To Lr
Lc = Ws.Cells(i, Columns.Count).End(xlToLeft).Column
b = (Lc - 7) / 2
For j = 1 To 7
Ws2.Cells(1, j).Value = Ws.Cells(1, j).Value
For c = 1 To b
If j = 1 Then
Ws2.Cells(d + c + 1, j).Value = Ws.Cells(i, 6 + 2 * c).Value
ElseIf j = 5 Then
Ws2.Cells(d + c + 1, j).Value = Ws.Cells(i, 7 + 2 * c).Value
Else
Ws2.Cells(d + c + 1, j).Value = Ws.Cells(i, j).Value
End If
Next c
Next j
d = d + b
Next i

End Sub
Thank you it works! Just a question this was a simplified example of the file I use. The "real" one has ~3000 rows and many more columns (up to AN). Is there a way I can easy expand the code to apply this to the whole file? Due to data privacy, I'm not able to share this.
 
Upvote 0
This Code work on Total file that you used also. Because i input Lastrow (Lr) based last row have data at your Sheet1 Column A. Go Save as your main file and test macro on it. then if you see errors or problem, report it.
if your structure of your main file is different, take example with exact column name until I change macro.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,018
Messages
6,122,703
Members
449,093
Latest member
Mnur

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