Transpose data

ced_lee

New Member
Joined
Nov 28, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello. I have a sample of data that are in rows but I need to list them into columns.
Basically I need to turn the 1st table into the 2nd table.
I have tried looking for ways to transpose but have not been successful. I hope some guru here can help me out. Note that I do not want to make my file into an XLSM, so VBA is not preferred. Thanks.
 

Attachments

  • Table1.jpg
    Table1.jpg
    71.2 KB · Views: 14
  • Table2.jpg
    Table2.jpg
    57.8 KB · Views: 13

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi ced_lee,

Welcome to MrExcel!!

See how this goes:

VBA Code:
Option Explicit
Sub Macro1()

    Dim i As Long, j As Long, k As Long 'Rows based
    Dim y As Long, x As Long 'Columns based
    Dim wsSrc As Worksheet, wsOutput As Worksheet
    Dim objBarCodes As Object
    
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
    
    Set wsSrc = ThisWorkbook.Sheets("Sheet1") 'Sheet name containing the data to be transposed (columns A to C). Change to suit if necessary.
    Set wsOutput = ThisWorkbook.Sheets("Sheet2") 'Sheet name for the transposed data. Change to suit if necessary.
    Set objBarCodes = CreateObject("System.Collections.ArrayList")
    
    j = wsSrc.Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
    
    For i = 2 To j
        If objBarCodes.Contains(CStr(wsSrc.Range("A" & i))) = False Then
            k = IIf(k = 0, 2, k + 1)
            For x = 0 To 2
                wsOutput.Cells(k, 1).Offset(0, x).Value = wsSrc.Cells(i, 1).Offset(0, x).Value
            Next x
            objBarCodes.Add CStr(wsSrc.Cells(i, 1))
        Else
            For y = 0 To 1
                x = x + 1
                wsOutput.Cells(k, x).Value = wsSrc.Cells(i, 2).Offset(0, y)
            Next y
        End If
    Next i
    
    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With

End Sub

Regards,

Robert
 
Upvote 0
A formula option:
Book1
ABCDEFGHIJK
1BarcodeQtyDiscountBarcodeQty1Disc1Qty2Dis2Qty3Disc3
2A150%A150%220%360%
3A220%B410%515%620%
4A360%C724%
5B410%
6B515%
7B620%
8C724%
Sheet4
Cell Formulas
RangeFormula
E2:K4E2=LET(u,UNIQUE(A2:A8),IFNA(HSTACK(u,DROP(REDUCE("",u,LAMBDA(a,b,VSTACK(a,TOROW(FILTER(B2:C8,A2:A8=b))))),1)),""))
Dynamic array formulas.
 
Upvote 0
Solution
A formula option:
Book1
ABCDEFGHIJK
1BarcodeQtyDiscountBarcodeQty1Disc1Qty2Dis2Qty3Disc3
2A150%A150%220%360%
3A220%B410%515%620%
4A360%C724%
5B410%
6B515%
7B620%
8C724%
Sheet4
Cell Formulas
RangeFormula
E2:K4E2=LET(u,UNIQUE(A2:A8),IFNA(HSTACK(u,DROP(REDUCE("",u,LAMBDA(a,b,VSTACK(a,TOROW(FILTER(B2:C8,A2:A8=b))))),1)),""))
Dynamic array formulas.
Hi Cubist
Can you elaborate on your method as i reckon it is what i need? For eg, do I need to select certain ranges? Or do I only enter the formula in E2 and drag?
My dataset has 20k plus of rows/barcodes, so I'll need to know what to do exactly.
Thank you.
 
Upvote 0
Enter formula in E2 only, don't need to drag. Leave enough space for it to spill down and right. Test on a small number of rows first. Once it's working, extend the reference to 20k rows.

PS: PowerQuery is another option and probably a lot more efficient.
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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