Rearrange Data to show Duplicates?

SpreadsheetNoob

New Member
Joined
Jan 16, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I need to rearrange data so that it shows duplicates rather than only unique values. For example, data that shows qualifications:

CategorySubcategoryJohnBobRich
MicrosoftExcel XX
MicrosoftWordXX

I want to change it to:

CategorySubcategoryName
MicrosoftExcelJohn
MicrosoftWordBob
MicrosoftExcelRich
MicrosoftWordRich

Not sure if this is possible, I tried using transpose, but it obviously doesn't move the way I want. Thanks for any help everyone!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Category"}, "Attribute", "Value"),
    #"Added Conditional Column" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each if [Value] = "X" then null else [Value]),
    #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Attribute] <> "Subcategory")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute", "Name"}, {"Custom", "Subcategory"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Category", "Subcategory", "Name"})
in
    #"Reordered Columns"

Book1
ABCDE
1CategorySubcategoryJohnBobRich
2MicrosoftExcelXX
3MicrosoftWordXX
4
5CategorySubcategoryName
6MicrosoftExcelJohn
7MicrosoftExcelRich
8MicrosoftWordBob
9MicrosoftWordRich
Sheet1
 
Upvote 0
Solution
Welcome to the MrExcel board!

Here is a macro that you could also try with a copy of your workbook.

VBA Code:
Sub Qualifications()
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long, k As Long
  
  a = Range("A1").CurrentRegion.Value
  ReDim b(1 To UBound(a) * (UBound(a, 2) - 2), 1 To 3)
  For j = 3 To UBound(a, 2)
    For i = 2 To UBound(a)
      If Len(a(i, j)) > 0 Then
        k = k + 1
        b(k, 1) = a(i, 1): b(k, 2) = a(i, 2): b(k, 3) = a(1, j)
      End If
    Next i
  Next j
  With Cells(1, Columns.Count).End(xlToLeft).Offset(, 2)
    .Offset(1).Resize(k, 3).Value = b
    .Resize(, 3).Value = Array("Category", "Subcategory", "Name")
    .CurrentRegion.Columns.AutoFit
  End With
End Sub

My sample data and results of the above code.

SpreadsheetNoob.xlsm
ABCDEFGHI
1CategorySubcategoryJohnBobRichCategorySubcategoryName
2MicrosoftExcelXXMicrosoftExcelJohn
3MicrosoftWordXXMicrosoftWordBob
4MicrosoftExcelRich
5MicrosoftWordRich
6
Sheet1
 
Upvote 0
Try it
VBA Code:
Option Explicit
Sub ABC()
    Dim sArr(), Res(), i&, j&, K&
    With Sheet1
        sArr = .Range("A1").CurrentRegion.Value
    End With
    ReDim Res(1 To (UBound(sArr, 1) - 1) * (UBound(sArr, 2) - 2) + 1, 1 To 3)
    K = 1
    For i = 2 To UBound(sArr, 1)
        For j = 3 To UBound(sArr, 2)
            If UCase(sArr(i, j)) = "X" Then
                K = K + 1
                Res(K, 1) = sArr(i, 1)
                Res(K, 2) = sArr(i, 2)
                Res(K, 3) = sArr(1, j)
            End If
        Next
    Next
    If K Then
        Res(1, 1) = "Category": Res(1, 2) = "Subcategory": Res(1, 3) = "Name"
        Sheet2.UsedRange.ClearContents
        Sheet2.Range("A1").Resize(K + 1, 3).Value = Res
    End If
End Sub
 
Upvote 0
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Category"}, "Attribute", "Value"),
    #"Added Conditional Column" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each if [Value] = "X" then null else [Value]),
    #"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Attribute] <> "Subcategory")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute", "Name"}, {"Custom", "Subcategory"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Category", "Subcategory", "Name"})
in
    #"Reordered Columns"

Book1
ABCDE
1CategorySubcategoryJohnBobRich
2MicrosoftExcelXX
3MicrosoftWordXX
4
5CategorySubcategoryName
6MicrosoftExcelJohn
7MicrosoftExcelRich
8MicrosoftWordBob
9MicrosoftWordRich
Sheet1
This was exactly what I needed! Thanks a lot!
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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