• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Data conversion Vertical to Horizontal Format

Dear Sir,

Attached two files want to convert the family details to vertical format

Regards
N3
 

Attachments

  • Automotive GMC Dtata.xlsx
    112.4 KB · Views: 6
Try:
Code:
Sub blah()
With ActiveSheet
  LR = .Cells(.Rows.Count, "A").End(xlUp).Row
  Set rngSceDataBody = .Range("A2").Resize(LR - 1, 31)
End With
Set rngEmpCode = rngSceDataBody.Columns(1)
Set Destn = Sheets.Add(after:=Sheets(Sheets.Count)).Cells(1)
Destn.Resize(, 6) = Array("Employee Code", "Full Name", "Gender", "Date of Birth", "Employee's Age", "Relation")
Set Destn = Destn.Offset(1)
For Colm = 2 To 27 Step 5
  rngEmpCode.Copy Destn
  rngSceDataBody.Columns(Colm).Resize(, 5).Copy Destn.Offset(, 1)
  Set Destn = Destn.Offset(LR - 1)
Next Colm
Destn.Parent.Columns("A:F").EntireColumn.AutoFit
End Sub
See also button in attached.
 

Attachments

  • Chandoo39616Automotive GMC Dtata.xlsm
    114.4 KB · Views: 2
Another option in formula solution.

1] In A3, copied down :

=IFERROR(INDEX('Horizontal Data'!$A$2:$A$398,INT((ROW(A1)-1)/6)+1),"")

2] In B3, copied across to E3 and all copied down :

=IF($A3="","",OFFSET('Horizontal Data'!$A$1,MATCH($A3,'Horizontal Data'!$A$2:$A$398,0),MATCH($F3,'Horizontal Data'!$B$1:$AE$1,0)+MATCH(B$2,'Horizontal Data'!$B$1:$AE$1,0)-5))

3] In F3, copied down :

=IF($A3="","",INDEX({"Self";"Spouse";"Child1";"Child2";"Father";"Mother"},MOD(ROW(A1)-1,6)+1))

ps. the attachment formulas haven't copied down fully, please copied down all formulas until blank.

Regards
Bosco
 

Attachments

  • HoriToVertData.xlsx
    111.4 KB · Views: 9
Last edited:
Try:
Code:
Sub blah()
With ActiveSheet
  LR = .Cells(.Rows.Count, "A").End(xlUp).Row
  Set rngSceDataBody = .Range("A2").Resize(LR - 1, 31)
End With
Set rngEmpCode = rngSceDataBody.Columns(1)
Set Destn = Sheets.Add(after:=Sheets(Sheets.Count)).Cells(1)
Destn.Resize(, 6) = Array("Employee Code", "Full Name", "Gender", "Date of Birth", "Employee's Age", "Relation")
Set Destn = Destn.Offset(1)
For Colm = 2 To 27 Step 5
  rngEmpCode.Copy Destn
  rngSceDataBody.Columns(Colm).Resize(, 5).Copy Destn.Offset(, 1)
  Set Destn = Destn.Offset(LR - 1)
Next Colm
Destn.Parent.Columns("A:F").EntireColumn.AutoFit
End Sub
See also button in attached.

Working Great

Thank you
 
Another option in formula solution.

1] In A3, copied down :

=IFERROR(INDEX('Horizontal Data'!$A$2:$A$398,INT((ROW(A1)-1)/6)+1),"")

2] In B3, copied across to E3 and all copied down :

=IF($A3="","",OFFSET('Horizontal Data'!$A$1,MATCH($A3,'Horizontal Data'!$A$2:$A$398,0),MATCH($F3,'Horizontal Data'!$B$1:$AE$1,0)+MATCH(B$2,'Horizontal Data'!$B$1:$AE$1,0)-5))

3] In F3, copied down :

=IF($A3="","",INDEX({"Self";"Spouse";"Child1";"Child2";"Father";"Mother"},MOD(ROW(A1)-1,6)+1))

ps. the attachment formulas haven't copied down fully, please copied down all formulas until blank.

Regards
Bosco
Working Sir,
Thank you,
 
Back
Top