Rotating Data from Horizontal to Vertical using VBA Code

Saacko

New Member
Joined
Feb 1, 2024
Messages
12
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone, please let me know if someone has a VBA code that can format data to how I need it. Here is what my new data set looks like, my current data is in rows 1-5 and in rows. It goes for hundreds of columns wide. 10-21 is an example of how I would like those columns to be moved:

Buy On Paper - RevD - Macro-Enabled.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
1Project Set-UpMaterial Contract 5Material Contract 4
21.Project Set-Up - NTP to IFR, Hours1. PSU - Project Set-Up0FSProcurement ExecutionPCRMT-MGR100Linear1.Material Contract 5 - NTP to IFR, Hours1. MC5 - Material Contract 5200FSProcurement ExecutionPCRMT-MGR49Linear1.Material Contract 4 - NTP to IFR, Hours1. MC4 - Material Contract 4280FSProcurement ExecutionPCRMT-MGR36Linear
32.Project Set-Up - IFR to Quote (Proposal Received), Hours2. PSU - 1.Project Set-Up - NTP to IFR, Hours100FSPCRMT-SPT 160Linear2.Material Contract 5 - IFR to Quote (Proposal Received), Hours2. MC5 - 1.Material Contract 5 - NTP to IFR, Hours340FSPCRMT-SPT 122Linear2.Material Contract 4 - IFR to Quote (Proposal Received), Hours2. MC4 - 1.Material Contract 4 - NTP to IFR, Hours320FSPCRMT-SPT 118Linear
43.Project Set-Up - Quote (Proposal Received) to Award, Hours3. PSU - 2.Project Set-Up - IFR to Quote (Proposal Received), Hours100FSPCRMT-SPT 20Linear3.Material Contract 5 - Quote (Proposal Received) to Award, Hours3. MC5 - 2.Material Contract 5 - IFR to Quote (Proposal Received), Ho280FSPCRMT-SPT 222Linear3.Material Contract 4 - Quote (Proposal Received) to Award, Hours3. MC4 - 2.Material Contract 4 - IFR to Quote (Proposal Received), Ho260FSPCRMT-SPT 218Linear
54.Project Set-Up - Award to Delivery or Completion, Hours4. PSU - 3.Project Set-Up - Quote (Proposal Received) to Award, Hours0FS4.Material Contract 5 - Award to Delivery or Completion, Hours4. MC5 - 3.Material Contract 5 - Quote (Proposal Received) to Award, 2920FS4.Material Contract 4 - Award to Delivery or Completion, Hours4. MC4 - 3.Material Contract 4 - Quote (Proposal Received) to Award, 1920FS
6
7
8
9Package NameAbbreviationDurationLogicLOE TitleResourceMan HoursCurve
101.Project Set-Up - NTP to IFR, Hours1. PSU - Project Set-Up0FSProcurement ExecutionPCRMT-MGR100Linear
112.Project Set-Up - IFR to Quote (Proposal Received), Hours2. PSU - 1.Project Set-Up - NTP to IFR, Hours100FSPCRMT-SPT 160Linear
123.Project Set-Up - Quote (Proposal Received) to Award, Hours3. PSU - 2.Project Set-Up - IFR to Quote (Proposal Received), Hours100FSPCRMT-SPT 20Linear
134.Project Set-Up - Award to Delivery or Completion, Hours4. PSU - 3.Project Set-Up - Quote (Proposal Received) to Award, Hours0FS
141.Material Contract 5 - NTP to IFR, Hours1. MC5 - Material Contract 5200FSProcurement ExecutionPCRMT-MGR49Linear
152.Material Contract 5 - IFR to Quote (Proposal Received), Hours2. MC5 - 1.Material Contract 5 - NTP to IFR, Hours340FSPCRMT-SPT 122Linear
163.Material Contract 5 - Quote (Proposal Received) to Award, Hours3. MC5 - 2.Material Contract 5 - IFR to Quote (Proposal Received), Ho280FSPCRMT-SPT 222Linear
174.Material Contract 5 - Award to Delivery or Completion, Hours4. MC5 - 3.Material Contract 5 - Quote (Proposal Received) to Award, 2920FS
181.Material Contract 4 - NTP to IFR, Hours1. MC4 - Material Contract 4280FSProcurement ExecutionPCRMT-MGR36Linear
192.Material Contract 4 - IFR to Quote (Proposal Received), Hours2. MC4 - 1.Material Contract 4 - NTP to IFR, Hours320FSPCRMT-SPT 118Linear
203.Material Contract 4 - Quote (Proposal Received) to Award, Hours3. MC4 - 2.Material Contract 4 - IFR to Quote (Proposal Received), Ho260FSPCRMT-SPT 218Linear
214.Material Contract 4 - Award to Delivery or Completion, Hours4. MC4 - 3.Material Contract 4 - Quote (Proposal Received) to Award, 1920FS
22
Final Data Set



My tab of the sheet is named "Final Data Set"

@kevin9999

Please let me know if you can help,

Thanks

Scout
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Please try the following on a copy of your workbook.

VBA Code:
Option Explicit
Sub Saacko_V2()
Dim ws As Worksheet, LCol As Long
Set ws = Worksheets("Final Data Set")
    LCol = ws.Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column
    Dim ArrIn(), arrOut(), arr()
    Dim nRng As Long, i As Long, j As Long
    nRng = LCol / 8
    ReDim ArrIn(1 To nRng)
    
    'Load the input array
    With ws
        j = 1
        For i = 1 To nRng
            ArrIn(i) = ws.Cells(2, j).Resize(4, 8)
            j = j + 8
        Next i
    End With
    
    'Load the output array
    Dim rw As Long, col As Long, r As Long
    ReDim arrOut(1 To LCol, 1 To 8)
    r = 1
    For i = 1 To nRng
        arr = ArrIn(i)
        For rw = 1 To UBound(arr, 1)
            For col = 1 To UBound(arr, 2)
                arrOut(r, col) = arr(rw, col)
                Next col
            r = r + 1
        Next rw
    Next i
    
    'Write the array to the sheet
    ws.Range("A10").Resize(LCol, 8).Value = arrOut
End Sub
 
Upvote 1
Solution
Thank you so much this worked literally perfect. I am so thankful once again.

Have a great one Kevin
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,579
Members
452,653
Latest member
craigje92

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