Transpose Columns with Duplicate Values into Single Row

dabigmonky

New Member
Joined
Nov 14, 2014
Messages
8
Hello, how can I transpose columns with duplicate values and remove duplicates while placing the remaining values into rows?

Here is what my data looks like:

Image%202014-11-19%20at%209.35.15%20AM.png


Here is what I'd like it to look like:

Image%202014-11-19%20at%209.37.59%20AM.png
 

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.
UDIPTI,

Thanks for your workbook/worksheet.

Here is a macro solution for you to consider.

With your data in the ActiveSheet in range A1:B24731, it took 18.461 seconds to process the data, into the resulting range A1:K3119.


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub ReorgData_UDIPTI()
' hiker95, 10/12/2016, ME819244
Dim r As Long, lr As Long, n As Long, lc As Long
Application.ScreenUpdating = False
With ActiveSheet
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  For r = 2 To lr
    n = Application.CountIf(.Columns(1), .Cells(r, 1).Value)
    If n > 1 Then
      .Cells(r, 2).Resize(, n).Value = Application.Transpose(.Range(.Cells(r, 2), .Cells(r + n - 1, 2)).Value)
      .Range("A" & r + 1 & ":B" & r + n - 1).ClearContents
    End If
    r = r + n - 1
  Next r
  lc = .Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
  On Error Resume Next
  .Range("A1", .Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  On Error GoTo 0
  .Cells(1, 3).Resize(, lc - 2).Value = .Cells(1, 2).Value
  .Columns(1).Resize(, lc).AutoFit
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the ReorgData_UDIPTI macro.


I would think that one of the Scripting.Dictionary Gurus would be able to create a much faster macro.
 
Last edited:
Upvote 0
UDIPTI,

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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