VBA Help: Transpose data from duplicate rows to Multiple new columns

MattGS

New Member
Joined
Mar 30, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hi, I have seen various formulas to do this but they only work with 1 column of Data. where there is a duplicate in Column A, take cells in columns D:G add them to the line above and delete Line, so I only end up with 1 Row and transposed data:
SearchResults.xlsm
ABCDEFG
1Part NumberDescriptionFootprint/Page SizePreferred Status (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)
23513-999-55580CAP 6N8 16V 2% ( 0805 )0805PreferredManufacturer Parts.ActivePanasonicECHU1C6N8GX5
33513-999-55583CAP 68N 16V 5%1210PreferredManufacturer Parts.ActivePanasonicECHU1C683JX5
43513-999-55584CAP 10N 16V 5%1210PreferredManufacturer Parts.ActivePanasonicECHU1C103JX5
53513-999-55585CAP 3N3 16V 5%0805PreferredManufacturer Parts.ActivePanasonicECHU1C332JX5
63513-999-60009CAP 3N9 2% PL FLM 16V0805PreferredManufacturer Parts.ActivePanasonicECHU1C392GX5
73513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R0CA01[]
83513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R0BA01[]
93513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ObsoleteSamsung Electro-Mechanics GmbHCL05C010BB5NNNC
103513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveAVX Kyocera04025A1R0BAT2A
113513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R0BA16[]
123513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R0BB01[]
133513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R2CA01[]
143513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R2BA01[]
153513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ObsoleteSamsung Electro-Mechanics GmbHCL05C1R2BB5NNNC
163513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveAVX Kyocera04025A1R2BAT2A
173513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R2BB01[]
183513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R2BA16[]
193513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R5CA01[]
203513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R5BA01-[]
213513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveSamsung Electro-Mechanics GmbHCL05C1R5BB5NNNC
223513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveAVX Kyocera04025A1R5BAT2A
233513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R5BB01[]
243513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R5BA16[]
253513-999-60108CAP 1p8 ±0p25 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R8CA01[]
263513-999-60108CAP 1p8 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R8BA01[]
273513-999-60108CAP 1p8 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R8BA16[]
283513-999-60108CAP 1p8 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R8BB01[]
293513-999-60108CAP 1p8 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ActiveAVX Kyocera04025A1R8BAT2A
303513-999-60108CAP 1p8 ±0p25 50V C0G ( 0402 )0402AlternateManufacturer Parts.ObsoleteSamsung Electro-Mechanics GmbHCL05C1R8BB5NNN[]
313513-999-60109CAP 2p2 ±0p25 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H2R2CA01[]
Sheet0


So would end up with something like:
SearchResults-7.xls
ABCDEFGHIJKLMNOPQRSTUVW
1Part NumberDescriptionProduct Line(s)Footprint/Page SizePreferred Status (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)
23513-999-55580CAP 6N8 16V 2% ( 0805 )Various/Misc0805PreferredPanasonicECHU1C6N8GX5Manufacturer Parts.Active
33513-999-55583CAP 68N 16V 5%Various/Misc1210PreferredPanasonicECHU1C683JX5Manufacturer Parts.Active
43513-999-55584CAP 10N 16V 5%Various/Misc1210PreferredPanasonicECHU1C103JX5Manufacturer Parts.Active
53513-999-55585CAP 3N3 16V 5%Various/Misc0805PreferredPanasonicECHU1C332JX5Manufacturer Parts.Active
63513-999-60009CAP 3N9 2% PL FLM 16VVarious/Misc0805PreferredPanasonicECHU1C392GX5Manufacturer Parts.Active
73513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )Various/Misc0402PreferredMurata Electronics UK LtdGRM1555C1H1R0CA01[]Manufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R0BA01[]Manufacturer parts.Active - Not Recommended for New DesignsSamsung Electro-Mechanics GmbHCL05C010BB5NNNCManufacturer Parts.ObsoleteAVX Kyocera04025A1R0BAT2AManufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R0BA16[]Manufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R0BB01[]Manufacturer Parts.Active
83513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )Various/Misc0402PreferredMurata Electronics UK LtdGRM1555C1H1R2CA01[]Manufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R2BA01[]Manufacturer parts.Active - Not Recommended for New DesignsSamsung Electro-Mechanics GmbHCL05C1R2BB5NNNCManufacturer Parts.ObsoleteAVX Kyocera04025A1R2BAT2AManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R2BB01[]Manufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R2BA16[]Manufacturer Parts.Active
93513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )Various/Misc0402PreferredMurata Electronics UK LtdGRM1555C1H1R5CA01[]Manufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R5BA01-[]Manufacturer parts.Active - Not Recommended for New DesignsSamsung Electro-Mechanics GmbHCL05C1R5BB5NNNCManufacturer Parts.ActiveAVX Kyocera04025A1R5BAT2AManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R5BB01[]Manufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R5BA16[]Manufacturer Parts.Active
Sheet0
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Change the sheet names (in red) to suit your needs.
Rich (BB code):
Sub TransposeData2()
    Application.ScreenUpdating = False
    Dim lRow As Long, i As Long, rCount As Long, dic As Object, v As Variant, srcWS As Worksheet, desWS As Worksheet, rng As Range
    Set srcWS = Sheets("Sheet1")
    Set desWS = Sheets("Sheet2")
    v = srcWS.Range("A2", srcWS.Range("A" & Rows.Count).End(xlUp)).Resize(, 7).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v) To UBound(v)
        If Not dic.exists(v(i, 1)) Then
            dic.Add v(i, 1), Nothing
            With srcWS.Cells(1).CurrentRegion
                .AutoFilter 1, v(i, 1)
                rCount = srcWS.[subtotal(103,A:A)] - 1
                If rCount = 1 Then
                    desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 5).Value = Array(v(i, 1), v(i, 2), "Various/Misc", v(i, 3), v(i, 4))
                Else
                    With desWS
                        lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
                        .Range("A" & lRow).Resize(, 5).Value = Array(v(i, 1), v(i, 2), "Various/Misc", v(i, 3), v(i, 4))
                        For Each rng In srcWS.Range("F2", srcWS.Range("F" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
                            .Cells(lRow, .Columns.Count).End(xlToLeft).Offset(, 1).Resize(, 3).Value = Array(rng, rng.Offset(, 1), rng.Offset(, -1))
                        Next rng
                    End With
                End If
            End With
        End If
    Next i
    desWS.Columns.AutoFit
    srcWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps,

thank you for the code was extremly useful, Apologies, i made an error in the output it shoud be the Product Lines column should not havbe been in output: it also eems to remove all the information for single source items, so as example 3513-999-55580 has no manufacturer information, you can see in current output file:
SearchResults.xlsm
ABCDEFG
1Part NumberDescriptionFootprint/Page SizePreferred Status (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)
23513-999-55580CAP 6N8 16V 2% ( 0805 )Various/MiscPreferredPreferred
Sheet1


so the output sheet should look like:
SearchResults-7.xls
ABCDEFGHIJKLMNOPQRSTUV
1Part NumberDescriptionFootprint/Page SizePreferred Status (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)Mfr. Part Lifecycle Phase (Manufacturers)Mfr. Name (Manufacturers)Mfr. Part Number (Manufacturers)
23513-999-55580CAP 6N8 16V 2% ( 0805 )0805PreferredManufacturer Parts.ActivePanasonicECHU1C6N8GX5
33513-999-55583CAP 68N 16V 5%1210PreferredManufacturer Parts.ActivePanasonicECHU1C683JX5
43513-999-55584CAP 10N 16V 5%1210PreferredManufacturer Parts.ActivePanasonicECHU1C103JX5
53513-999-55585CAP 3N3 16V 5%0805PreferredManufacturer Parts.ActivePanasonicECHU1C332JX5
63513-999-60009CAP 3N9 2% PL FLM 16V0805PreferredManufacturer Parts.ActivePanasonicECHU1C392GX5
73513-999-60105CAP 1p ±0p25 C 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R0CA01[]Manufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R0BA01[]Manufacturer Parts.ObsoleteSamsung Electro-Mechanics GmbHCL05C010BB5NNNCManufacturer Parts.ActiveAVX Kyocera04025A1R0BAT2AManufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R0BA16[]Manufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R0BB01[]
83513-999-60106CAP 1p2 ±0p25 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R2CA01[]Manufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R2BA01[]Manufacturer Parts.ObsoleteSamsung Electro-Mechanics GmbHCL05C1R2BB5NNNCManufacturer Parts.ActiveAVX Kyocera04025A1R2BAT2AManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R2BB01[]Manufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R2BA16[]
93513-999-60107CAP 1p5 ±0p25 C 50V C0G ( 0402 )0402PreferredManufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R5CA01[]Manufacturer parts.Active - Not Recommended for New DesignsMurata Electronics UK LtdGRM1555C1H1R5BA01-[]Manufacturer Parts.ActiveSamsung Electro-Mechanics GmbHCL05C1R5BB5NNNCManufacturer Parts.ActiveAVX Kyocera04025A1R5BAT2AManufacturer Parts.ActiveMurata Electronics UK LtdGJM1555C1H1R5BB01[]Manufacturer Parts.ActiveMurata Electronics UK LtdGCM1555C1H1R5BA16[]
Sheet0
 
Upvote 0
Try:
VBA Code:
Sub TransposeData()
    Application.ScreenUpdating = False
    Dim lRow As Long, i As Long, rCount As Long, dic As Object, v As Variant, srcWS As Worksheet, desWS As Worksheet, rng As Range
    Set srcWS = Sheets("Sheet1")
    Set desWS = Sheets("Sheet2")
    v = srcWS.Range("A2", srcWS.Range("A" & Rows.Count).End(xlUp)).Resize(, 7).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v) To UBound(v)
        If Not dic.exists(v(i, 1)) Then
            dic.Add v(i, 1), Nothing
            With srcWS.Cells(1).CurrentRegion
                .AutoFilter 1, v(i, 1)
                rCount = srcWS.[subtotal(103,A:A)] - 1
                If rCount = 1 Then
                    desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 7).Value = Array(v(i, 1), v(i, 2), v(i, 3), v(i, 4), v(i, 5), v(i, 6), v(i, 7))
                Else
                    With desWS
                        lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
                        .Range("A" & lRow).Resize(, 7).Value = Array(v(i, 1), v(i, 2), v(i, 3), v(i, 4), v(i, 5), v(i, 6), v(i, 7))
                        For Each rng In srcWS.Range("F2", srcWS.Range("F" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
                            .Cells(lRow, .Columns.Count).End(xlToLeft).Offset(, 1).Resize(, 3).Value = Array(rng.Offset(, -1), rng, rng.Offset(, 1))
                        Next rng
                    End With
                End If
            End With
        End If
    Next i
    desWS.Columns.AutoFit
    srcWS.Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps,

wanted to write to say a huge thank you this has really helped.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,124
Members
453,021
Latest member
Justyna P

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