Transpose Onto Sheet 2 Please.

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,783
Office Version
  1. 365
Platform
  1. Windows
I have sheet 1 with 2 columns, a number in A and a transmission in column B. I need the number and the transmission transposed onto sheet 2. There may be a unique number in A or several the same with different transmissions in B. In the example I have highlighted the duplicates in A. The yellow one has the same number in A but 3 transmissions in B so they will go under the transmission header in B (also yellow), the same with blue, green and orange.

Sheet A will consist of several hundred thousand rows with more permutations so this is just a small example. It would be helpful if the headers got created on sheet 2 please. Thanks.

The combination of headers will just include -

Direct Drive
CVT
Manual
Semi-Automatic
Automatic

CodeTransmission
M10105420000001CVT
M10105420000002CVT
M10105420000003CVT
M10105420000003Direct Drive
M10105420000004CVT
M10200400000008Manual
M10200400000008Semi-Automatic
M10200400000008CVT
M10200400000009Manual
M10200400000009Semi-Automatic
M10200400000010Manual
M10200400000011Manual
M10200400000012Manual
M10200400000012Automatic
M10200400000013Direct Drive


After

CVTManual & Semi-Automatic & CVTManual & Semi-AutomaticManualManual & AutomaticCVT & Direct DriveDirect Drive
M10105420000001M10200400000008M10200400000009M10200400000010M10200400000012M10105420000003M10200400000013
M10105420000002M10200400000011
M10105420000004
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this (replace A2:A16 with your actual Code range and B2:B16 by your actual Transmission range):

=LET(x,A2:A16,y,B2:B16,code,UNIQUE(x),array,HSTACK(BYROW(code,LAMBDA(a,TEXTJOIN(" & ",TRUE,FILTER(y,x=a)))),code),headers,UNIQUE(HSTACK(CHOOSECOLS(array,1))),TRANSPOSE(IFERROR(HSTACK(headers,DROP(REDUCE("",headers,LAMBDA(a,b,VSTACK(a,TRANSPOSE(FILTER(CHOOSECOLS(array,2),CHOOSECOLS(array,1)=b))))),1)),"")))
 
Upvote 0
Try this (replace A2:A16 with your actual Code range and B2:B16 by your actual Transmission range):

=LET(x,A2:A16,y,B2:B16,code,UNIQUE(x),array,HSTACK(BYROW(code,LAMBDA(a,TEXTJOIN(" & ",TRUE,FILTER(y,x=a)))),code),headers,UNIQUE(HSTACK(CHOOSECOLS(array,1))),TRANSPOSE(IFERROR(HSTACK(headers,DROP(REDUCE("",headers,LAMBDA(a,b,VSTACK(a,TRANSPOSE(FILTER(CHOOSECOLS(array,2),CHOOSECOLS(array,1)=b))))),1)),"")))
Thanks but I think I need a macro in this case as I have thousands of rows with multiple combinations.
 
Upvote 0
Try this code:
VBA Code:
Sub TransposeData()
    Dim wsInput As Worksheet, wsOutput As Worksheet
    Dim dict As Object
    Dim trans As Variant
    Dim dataRange As Range
    Dim lastRow As Long, i As Long, nextCol As Long, nextRow As Long
    Dim inputArray As Variant
    Dim outputArray() As Variant
    Dim maxRows As Long, maxCols As Long

    Set dict = CreateObject("Scripting.Dictionary")
    Set wsInput = ThisWorkbook.Sheets("Sheet1") ' Input sheet name
    Set wsOutput = ThisWorkbook.Sheets("Sheet2") ' Output sheet name
    lastRow = wsInput.Cells(wsInput.Rows.Count, "A").End(xlUp).Row
    Set dataRange = wsInput.Range("A2:B" & lastRow)
    inputArray = dataRange.Value
    
    For i = 1 To UBound(inputArray, 1)
        trans = inputArray(i, 2)
        If Not dict.Exists(trans) Then
            dict(trans) = ""
        End If
        dict(trans) = dict(trans) & inputArray(i, 1) & ","
    Next i
 
    maxCols = dict.Count
    For Each trans In dict.keys
        maxRows = WorksheetFunction.Max(maxRows, UBound(Split(dict(trans), ",")))
    Next trans

    ReDim outputArray(1 To maxRows + 1, 1 To maxCols)
    nextCol = 1
    For Each trans In dict.keys
        outputArray(1, nextCol) = trans
        nextRow = 2
        For Each cell In Split(dict(trans), ",")
            If Len(cell) > 0 Then
                outputArray(nextRow, nextCol) = cell
                nextRow = nextRow + 1
            End If
        Next cell
        nextCol = nextCol + 1
    Next trans
    
    wsOutput.Range("A1").Resize(UBound(outputArray, 1), UBound(outputArray, 2)).Value = outputArray
End Sub

With a few thousand rows, I think FILTER would be ok. An option for formula.
Book1
ABCDEFGH
1CodeTransmissionCVTDirect DriveManualSemi-AutomaticAutomatic
2M10105420000001CVTM10105420000001M10105420000003M10200400000008M10200400000008M10200400000012
3M10105420000002CVTM10105420000002M10200400000013M10200400000009M10200400000009
4M10105420000003CVTM10105420000003M10200400000010
5M10105420000003Direct DriveM10105420000004M10200400000011
6M10105420000004CVTM10200400000008M10200400000012
7M10200400000008Manual
8M10200400000008Semi-Automatic
9M10200400000008CVT
10M10200400000009Manual
11M10200400000009Semi-Automatic
12M10200400000010Manual
13M10200400000011Manual
14M10200400000012Manual
15M10200400000012Automatic
16M10200400000013Direct Drive
Sheet1
Cell Formulas
RangeFormula
D1:H1D1=TOROW(UNIQUE(B2:B16))
D2:D6,H2,G2:G3,F2:F6,E2:E3D2=FILTER($A$2:$A$16,$B$2:$B$16=D1)
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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