Converting horizontal data to vertical data with repeating data

Traceelewis71

New Member
Joined
Dec 5, 2017
Messages
12
I currently have a report of 8000 plus employees who have 12 rows of data each. each row of data has 3 columns that are represented for each month of the year. This is how my current reporting feature creates the report. the software I need to upload this data into is in the format below this chart.
YEARMONTHLINE 14LINE 15LINE 16STATUSEE ID
201711C165.132HFA02209
201721C166.082HFA02209
201731C62.342HFA02209
201741C02HFA02209
201751C02HFA02209
201761C02HFA02209
201771H2AFA02209
201781H2AFA02209
201791H2AFA02209
2017101H2BFA02209
2017111H2BPA02209
2017121H2BPA02209

<tbody>
</tbody>

<tbody>
</tbody>


I need this data to now be in this format

EE IDMONTH 1 LINE 14MONTH 1 LINE 15MONTH 1 LINE 16MONTH 2 LINE 14MONTH 2 LINE 15MONTH 2 LINE 16MONTH 3 LINE 14MONTH 3 LINE 15MONTH 3 LINE 16MONTH 4 LINE 14MONTH 4 LINE 15MONTH 4 LINE 16MONTH 1 LINE 14MONTH 5 LINE 15MONTH 5 LINE 16MONTH 6 LINE 14MONTH 6 LINE 15MONTH 6 LINE 16MONTH 7 LINE 14MONTH 7 LINE 15MONTH 7 LINE 16MONTH 8 LINE 14MONTH 8 LINE 15MONTH 8 LINE 16MONTH 9 LINE 14MONTH 9 LINE 15MONTH 9 LINE 16MONTH 10 LINE 14MONTH 10 LINE 15MONTH 10 LINE 16MONTH 11 LINE 14MONTH 11 LINE 15MONTH 11 LINE 16MONTH 12 LINE 14MONTH 12 LINE 15MONTH 12 LINE 16
A022091C165.132H1C166.082H1C62.342H1C02H1C02H1C02H1H2A1H2A1H2A1H2A1H2A1H2A
B141141C159.842H1C163.092H1C179.432H1C179.562H1C154.742H1C179.932H1C174.072H1C175.322H1C189.662H1C167.592H1C178.182H1C182.552H
F138301E02C1E02C1E02C1E02C1E02C1E02C1E02C1E02C1E02C1E02C1E02C1E02C
H140721C172.912H1C155.612H1C159.62H1C177.062H1C106.982H1H2A1H2A1H2A1H2A1H2A1H2A1H2A

<tbody>
</tbody>

<tbody>
</tbody>

I am currently keying the data as I can't figure out a formula to get this data converted. This will take me weeks to do and leaves too much room for error. I've tried an index match formula but that's not working. I don't even know where to begin. Should I use access or SQL. I don't think SumIF formula will work because I don't want the employees' data totaled up.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Traceelewis71,

You might consider a macro approach...

Code:
Sub TransposeData_1062902()
Application.ScreenUpdating = False
Dim arr1 As Variant, arr2 As Variant
Dim LastRow As Long, r1 As Long, c1 As Long, r2 As Long, c2 As Long
Dim i As Long, j As Long, k As Long, n As Long

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
arr1 = Range("A2:G" & LastRow).Value
ReDim arr2(1 To UBound(arr1) / 12, 1 To 37)
r2 = 1
c2 = 2

''''Transpose data
For r1 = LBound(arr1) To UBound(arr1)
    For c1 = 3 To 5
        arr2(r2, 1) = arr1(r1, 7)
        arr2(r2, c2) = arr1(r1, c1)
        c2 = c2 + 1
        If c1 Mod 5 = 0 Then GoTo nxt1
    Next c1
nxt1:
    If r1 Mod 12 = 0 Then
        r2 = r2 + 1
        c2 = 2
    End If
Next r1

''''Add new worksheet, paste transposed data
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Range("A2:AK" & UBound(arr1) / 12 + 1).Value = arr2

''''Add headers
ActiveSheet.Cells(1, 1).Value = "EE ID"
i = 2
n = 1
Do While i < 37
    j = 14
    k = 1
    Do Until k = 4
        ActiveSheet.Cells(1, i) = "Month " & n & " Line " & j
        j = j + 1
        i = i + 1
        k = k + 1
    Loop
    n = n + 1
Loop
ActiveSheet.Rows("1:1").WrapText = True
End Sub

If you're not familiar with macros, please see the Adding Code to an Excel Workbook tutorial on the Contextures website, and in particular, the section titled Copy Excel VBA Code to a Regular Module.

Briefly, this macro copies the existing data into an array (an array is a special memory allocation) then line by line transposes the data into your requested format. A new sheet is added and the reformatted data is pasted, then headers are added.

Cheers,

tonyyy
 
Last edited:
Upvote 0
You're very welcome, Traceelewis71...
 
Upvote 0

Forum statistics

Threads
1,214,393
Messages
6,119,261
Members
448,880
Latest member
aveternik

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