Row Population and Transposing of data

ibesmond

New Member
Joined
Nov 26, 2010
Messages
17
Hello

I have a data set that has some problems and needs cleanup, but I'm not sure how to accomplish this feat.

Basically I want to flatten the data as much as possible without loosing any data.
The data came from different sources so each row represents a row, and the column is where the data is located.
If This was a small set I would just go manually, but this is only a small subset of the data.
The sources are in no particular order.

The first data set is problem.
The second data set is solution 1. If I could get the data to this position I would be happy, but
The third tab is solution 2, if I could get it to this stage that would be the ultimate goal.

NameGenreBorn DateDied DateBorn LocationDied LocationParentsFavorite SongsCause of deathReligionMovies
Bob MarleyReggae
Bob MarleyMelanomaRastafariMarley
Bob MarleyNorval Marley, Cedella BookerCorner Stone
Bob Marley
2/6/1945​
5/11/1981​
Nine Mile, JamaicaMiami, FL
Bob MarleyRedemption Song
Buju BantonReggae
Buju Banton
7/15/1973​
Kingston, Jamaica
Buju BantonUntold Stories
Bunny WailerReggae
Bunny Wailer
4/10/1947​
Kingston, Jamaica
Bunny WailerCool Runnings
Burning SpearReggaeOld Marcus Garvey
Burning Spear
3/1/1945​
St. Ann Parish, Jamaica
Damian MarleyReggae
Damian Marley
7/21/1978​
Kingston, Jamaica
Damian MarleyBob Marley, Cindy BreakspeareWelcome to Jam Rock
Damian MarleyMedication
Dennis Brown
Dennis BrownReggaePneumothorax
Dennis BrownThe Promised Land
Dennis Brown
2/1/1957​
7/1/1999​
Kingston, JamaicaKingston, Jamaica
Desmend DekkerReggae
Desmend Dekker
7/16/1941​
5/25/2006​
St. Andrew Parish, JamaicaThornton Heath, United Kingdom
Desmend DekkerIsrealites
Jimmy CliffReggae
Jimmy Cliff
4/1/1948​
St. James Parish, Jamaica
Jimmy CliffI can See Clearly Now
Jimmy Cliff
Lee "Scratch" PerryReggae
Lee "Scratch" Perry
3/20/1936​
Kendal, Jamaica
Lee "Scratch" PerryChase the DevilLee Scratch Perry's Vision of Paradise
Lee "Scratch" Perry
Peter ToshReggae
Peter ToshYou Can't Blame the Youth
Peter Tosh
10/19/1944​
9/11/1987​
Grange Hill, JamaicaKingston, Jamaica
Peter ToshMurderRastafariStepping Razor: Red X
Peter ToshLegalize it
Peter ToshGlass House
Peter Tosh
Stephen MarleyReggae
Stephen Marley
5/19/1972​
Wilmington, DE
Stephen MarleyMind Control
Stephen MarleyMedication
Stephen MarleyChase Dem
Stephen MarleyIron Bars
Stephen MarleyInna Di Red
Ziggy MarleyReggae
Ziggy Marley
10/17/1968​
Kingston, Jamaica
Ziggy MarleyLooking
Ziggy MarleyTrue to Myself
Ziggy MarleyDragonfly
Ziggy MarleyKeep My Faith
Ziggy MarleyShark Tale
Ziggy MarleyLife and Debt
Ziggy MarleyI Am Bolt
Ziggy MarleyPup Star
Ziggy MarleyThe Strink is In

2nd Set

NameGenreBorn DateDied DateBorn LocationDied LocationParentsFavorite SongsCause of deathReligionMovies
Bob MarleyReggae
2/6/1945​
5/11/1981​
Nine Mile, JamaicaMiami, FLNorval Marley, Cedella BookerCorner StoneMelanomaRastafariMarley
Bob MarleyReggae
2/6/1945​
5/11/1981​
Nine Mile, JamaicaMiami, FLNorval Marley, Cedella BookerRedemption SongMelanomaRastafariMarley
Buju BantonReggae
7/15/1973​
Kingston, JamaicaUntold Stories
Bunny WailerReggae
4/10/1947​
Kingston, JamaicaCool Runnings
Burning SpearReggae
3/1/1945​
St. Ann Parish, JamaicaOld Marcus Garvey
Damian MarleyReggae
7/21/1978​
Kingston, JamaicaBob Marley, Cindy BreakspeareWelcome to Jam Rock
Damian MarleyReggae
7/21/1978​
Kingston, JamaicaBob Marley, Cindy BreakspeareMedication
Dennis BrownReggae
2/1/1957​
7/1/1999​
Kingston, JamaicaKingston, JamaicaThe Promised LandPneumothorax
Desmend DekkerReggae
7/16/1941​
5/25/2006​
St. Andrew Parish, JamaicaThornton Heath, United KingdomIsrealites
Jimmy CliffReggae
4/1/1948​
St. James Parish, JamaicaI can See Clearly Now
Lee "Scratch" PerryReggae
3/20/1936​
Kendal, JamaicaChase the DevilLee Scratch Perry's Vision of Paradise
Peter ToshReggae
10/19/1944​
9/11/1987​
Grange Hill, JamaicaKingston, JamaicaYou Can't Blame the YouthMurderRastafariStepping Razor: Red X
Peter ToshReggae
10/19/1944​
9/11/1987​
Grange Hill, JamaicaKingston, JamaicaLegalize itMurderRastafariStepping Razor: Red X
Peter ToshReggae
10/19/1944​
9/11/1987​
Grange Hill, JamaicaKingston, JamaicaGlass HouseMurderRastafariStepping Razor: Red X
Stephen MarleyReggae
5/19/1972​
Wilmington, DEMind Control
Stephen MarleyReggae
5/19/1972​
Wilmington, DEMedication
Stephen MarleyReggae
5/19/1972​
Wilmington, DEChase Dem
Stephen MarleyReggae
5/19/1972​
Wilmington, DEIron Bars
Stephen MarleyReggae
5/19/1972​
Wilmington, DEInna Di Red
Ziggy MarleyReggae
10/17/1968​
Kingston, JamaicaLookingShark Tale
Ziggy MarleyReggae
10/17/1968​
Kingston, JamaicaTrue to MyselfLife and Debt
Ziggy MarleyReggae
10/17/1968​
Kingston, JamaicaDragonflyI Am Bolt
Ziggy MarleyReggae
10/17/1968​
Kingston, JamaicaKeep My FaithPup Star
Ziggy MarleyReggae
10/17/1968​
Kingston, JamaicaKeep My FaithThe Strink is In

3rd Set

NameGenreBorn DateDied DateBorn LocationDied LocationParentsFavorite Songs1Favorite Songs2Favorite Songs3Favorite Songs4Favorite Songs5Cause of deathReligionMovies1Movies12Movies3Movies4Movies5
Bob MarleyReggae
2/6/1945​
5/11/1981​
Nine Mile, JamaicaMiami, FLNorval Marley, Cedella BookerCorner StoneRedemption SongMelanomaRastafariMarley
Buju BantonReggae
7/15/1973​
Kingston, JamaicaUntold Stories
Bunny WailerReggae
4/10/1947​
Kingston, JamaicaCool Runnings
Burning SpearReggae
3/1/1945​
St. Ann Parish, JamaicaOld Marcus Garvey
Damian MarleyReggae
7/21/1978​
Kingston, JamaicaBob Marley, Cindy BreakspeareWelcome to Jam RockMedication
Dennis BrownReggae
2/1/1957​
7/1/1999​
Kingston, JamaicaKingston, JamaicaThe Promised LandPneumothorax
Desmend DekkerReggae
7/16/1941​
5/25/2006​
St. Andrew Parish, JamaicaThornton Heath, United KingdomIsrealites
Jimmy CliffReggae
4/1/1948​
St. James Parish, JamaicaI can See Clearly NowMarley
Lee "Scratch" PerryReggae
3/20/1936​
Kendal, JamaicaChase the DevilLee Scratch Perry's Vision of Paradise
Peter ToshReggae
10/19/1944​
9/11/1987​
Grange Hill, JamaicaKingston, JamaicaYou Can't Blame the YouthLegalize itGlass HouseMurderRastafariStepping Razor: Red X
Stephen MarleyReggae
5/19/1972​
Wilmington, DEMind ControlMedicationChase DemIron BarsInna Di Red
Ziggy MarleyReggae
10/17/1968​
Kingston, JamaicaLookingTrue to MyselfDragonflyKeep My FaithShark TaleLife and DebtI Am BoltPup StarThe Strink is In

I appreciate the advise. Thank you
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
something like this or you need to split songs and movies?
list.png
 
Upvote 0
Looks familiar.

Book2
ABCDEFGHIJK
1NameGenreBorn DateDied DateBorn LocationDied LocationParentsFavorite SongsCause of deathReligionMovies
2Bob MarleyReggae2/6/19455/11/1981Nine Mile, JamaicaMiami, FLNorval Marley, Cedella BookerCorner Stone,Redemption SongMelanomaRastafariMarley
3Buju BantonReggae7/15/1973Kingston, JamaicaUntold Stories
4Bunny WailerReggae4/10/1947Kingston, JamaicaCool Runnings
5Burning SpearReggae3/1/1945St. Ann Parish, JamaicaOld Marcus Garvey
6Damian MarleyReggae7/21/1978Kingston, JamaicaBob Marley, Cindy BreakspeareWelcome to Jam Rock,Medication
7Dennis BrownReggae2/1/19577/1/1999Kingston, JamaicaKingston, JamaicaThe Promised LandPneumothorax
8Desmend DekkerReggae7/16/19415/25/2006St. Andrew Parish, JamaicaThornton Heath, United KingdomIsrealites
9Jimmy CliffReggae4/1/1948St. James Parish, JamaicaI can See Clearly Now
10Lee "Scratch" PerryReggae3/20/1936Kendal, JamaicaChase the DevilLee Scratch Perry's Vision of Paradise
11Peter ToshReggae10/19/19449/11/1987Grange Hill, JamaicaKingston, JamaicaYou Can't Blame the Youth,Legalize it,Glass HouseMurderRastafariStepping Razor: Red X
12Stephen MarleyReggae5/19/1972Wilmington, DEMind Control,Medication,Chase Dem,Iron Bars,Inna Di Red
13Ziggy MarleyReggae10/17/1968Kingston, JamaicaLooking,True to Myself,Dragonfly,Keep My FaithShark Tale,Life and Debt,I Am Bolt,Pup Star,The Strink is In
Sheet4
 
Upvote 0
it's only a matter of delimiter :)
imho, after comma should be a space ;)
 
Last edited:
Upvote 0
Agreed. I saw that after posting and it made the OCD go off.
 
Upvote 0
Here a macro for you to consider.

Your data on "set1" sheet starting at A1, results on "set3" sheet.
If the songs or movies are more or less than 5, the macro automatically adjusts the columns.

VBA Code:
Sub Row_Population_Transposing_Data()
  Dim a As Variant, b As Variant, c As Variant, d As Variant, e As Variant
  Dim dic As Object, sh As Worksheet
  Dim i As Long, j As Long, k As Long, lr As Long, m As Long, n As Long, u As Long
 
  Set sh = Sheets("Set1")
  With sh
    lr = .Range("A" & Rows.Count).End(3).Row
    a = .Range("A2:K" & lr).Value2
    m = Evaluate(Replace("=MAX(COUNTIFS(@,@," & .Name & "!H2:H" & lr & ",""<>""))", "@", .Name & "!A2:A" & lr)) 'max songs
    n = Evaluate(Replace("=MAX(COUNTIFS(@,@," & .Name & "!K2:K" & lr & ",""<>""))", "@", .Name & "!A2:A" & lr)) 'max movies
    u = Evaluate(Replace("=SUMPRODUCT((@<>"""")/COUNTIF(@,@&""""))", "@", .Name & "!A2:A" & lr)) 'unique
  End With
  ReDim b(1 To u, 1 To 7)
  ReDim c(1 To u, 1 To m)
  ReDim d(1 To u, 1 To 2)
  ReDim e(1 To u, 1 To n)
  Set dic = CreateObject("Scripting.Dictionary")
 
  For i = 1 To UBound(a, 1)
    If Not dic.exists(a(i, 1)) Then
      j = j + 1
      dic(a(i, 1)) = j
    End If
    j = dic(a(i, 1))
    For k = 1 To 7
      If a(i, k) <> "" Then b(j, k) = a(i, k)
    Next
    If a(i, 8) <> "" Then
      For k = 1 To m
        If c(j, k) = "" Then
          c(j, k) = a(i, 8)
          Exit For
        End If
      Next
    End If
    For k = 1 To 2
      If a(i, k + 8) <> "" Then d(j, k) = a(i, k + 8)
    Next
    If a(i, 11) <> "" Then
      For k = 1 To n
        If e(j, k) = "" Then
          e(j, k) = a(i, 11)
          Exit For
        End If
      Next
    End If
  Next
 
  With Sheets("Set3")
    'Headears
    .Range("A1").Resize(1, 7).Value = sh.Range("A1:G1").Value
    .Range("H1").Resize(1, m).Value = sh.Range("H1").Value
    .Cells(1, 8 + m).Resize(1, 2).Value = sh.Range("I1:J1").Value
    .Cells(1, 8 + m + 2).Resize(1, n).Value = sh.Range("K1").Value
    'Data
    .Range("A2").Resize(u, 7).Value = b
    .Range("H2").Resize(u, m).Value = c
    .Cells(2, 8 + m).Resize(u, 2).Value = d
    .Cells(2, 8 + m + 2).Resize(u, n).Value = e
  End With
End Sub
 
Last edited:
Upvote 0
NameGenreBorn DateDied DateBorn LocationDied LocationParentsFavorite Songs.1Favorite Songs.2Favorite Songs.3Favorite Songs.4Favorite Songs.5Cause of deathReligionMovies.1Movies.2Movies.3Movies.4Movies.5
Bob MarleyReggae2/6/19455/11/1981Nine Mile, JamaicaMiami, FLNorval Marley, Cedella BookerCorner StoneRedemption SongMelanomaRastafariMarley
Buju BantonReggae7/15/1973Kingston, JamaicaUntold Stories
Bunny WailerReggae4/10/1947Kingston, JamaicaCool Runnings
Burning SpearReggae3/1/1945St. Ann Parish, JamaicaOld Marcus Garvey
Damian MarleyReggae7/21/1978Kingston, JamaicaBob Marley, Cindy BreakspeareWelcome to Jam RockMedication
Dennis BrownReggae2/1/19577/1/1999Kingston, JamaicaKingston, JamaicaThe Promised LandPneumothorax
Desmend DekkerReggae7/16/19415/25/2006St. Andrew Parish, JamaicaThornton Heath, United KingdomIsrealites
Jimmy CliffReggae4/1/1948St. James Parish, JamaicaI can See Clearly Now
Lee "Scratch" PerryReggae3/20/1936Kendal, JamaicaChase the DevilLee Scratch Perry's Vision of Paradise
Peter ToshReggae10/19/19449/11/1987Grange Hill, JamaicaKingston, JamaicaYou Can't Blame the YouthLegalize itGlass HouseMurderRastafariStepping Razor: Red X
Stephen MarleyReggae5/19/1972Wilmington, DEMind ControlMedicationChase DemIron BarsInna Di Red
Ziggy MarleyReggae10/17/1968Kingston, JamaicaLookingTrue to MyselfDragonflyKeep My FaithShark TaleLife and DebtI Am BoltPup StarThe Strink is In

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Name"}, {{"Count", each _, type table}}),
    GenreExtract = Table.TransformColumns(Table.AddColumn(Group, "Genre", each [Count][Genre]), {"Genre", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    BornDateExtract = Table.TransformColumns(Table.AddColumn(GenreExtract, "Born Date", each [Count][Born Date]), {"Born Date", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    DiedDateExtract = Table.TransformColumns(Table.AddColumn(BornDateExtract, "Died Date", each [Count][Died Date]), {"Died Date", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    BornLocationExtract = Table.TransformColumns(Table.AddColumn(DiedDateExtract, "Born Location", each [Count][Born Location]), {"Born Location", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    DiedLocationExtract = Table.TransformColumns(Table.AddColumn(BornLocationExtract, "Died Location", each [Count][Died Location]), {"Died Location", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    ParentsExtract = Table.TransformColumns(Table.AddColumn(DiedLocationExtract, "Parents", each [Count][Parents]), {"Parents", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    SongsExtract = Table.TransformColumns(Table.AddColumn(ParentsExtract, "Favorite Songs", each [Count][Favorite Songs]), {"Favorite Songs", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    MaxCount1 = List.Max(Table.AddColumn(SongsExtract, "SCount", each List.Count(Text.Split([Favorite Songs],",")))[SCount]),
    SplitTCSongs = Table.SplitColumn(SongsExtract, "Favorite Songs", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), MaxCount1),
    CauseExtract = Table.TransformColumns(Table.AddColumn(SplitTCSongs, "Cause of death", each [Count][Cause of death]), {"Cause of death", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    ReligionExtract = Table.TransformColumns(Table.AddColumn(CauseExtract, "Religion", each [Count][Religion]), {"Religion", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    MoviesExtract = Table.TransformColumns(Table.AddColumn(ReligionExtract, "Movies", each [Count][Movies]), {"Movies", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    MaxCount2 = List.Max(Table.AddColumn(MoviesExtract, "SCount", each List.Count(Text.Split([Movies],",")))[SCount]),
    SplitTCMovies = Table.SplitColumn(MoviesExtract, "Movies", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), MaxCount2)
in
    SplitTCMovies
 
Upvote 0
Here is my version.

Book1
ABCDEFGHIJKLMNOPQRS
1NameGenreBorn DateDied DateBorn LocationDied LocationParentsFavorite Songs.1Favorite Songs.2Favorite Songs.3Favorite Songs.4Favorite Songs.5Cause of deathReligionMovies.1Movies.2Movies.3Movies.4Movies.5
2Bob MarleyReggae2/6/19455/11/1981Nine Mile, JamaicaMiami, FLNorval Marley, Cedella BookerCorner StoneRedemption SongMelanomaRastafariMarley
3Buju BantonReggae7/15/1973Kingston, JamaicaUntold Stories
4Bunny WailerReggae4/10/1947Kingston, JamaicaCool Runnings
5Burning SpearReggae3/1/1945St. Ann Parish, JamaicaOld Marcus Garvey
6Damian MarleyReggae7/21/1978Kingston, JamaicaBob Marley, Cindy BreakspeareWelcome to Jam RockMedication
7Dennis BrownReggae2/1/19577/1/1999Kingston, JamaicaKingston, JamaicaThe Promised LandPneumothorax
8Desmend DekkerReggae7/16/19415/25/2006St. Andrew Parish, JamaicaThornton Heath, United KingdomIsrealites
9Jimmy CliffReggae4/1/1948St. James Parish, JamaicaI can See Clearly Now
10Lee "Scratch" PerryReggae3/20/1936Kendal, JamaicaChase the DevilLee Scratch Perry's Vision of Paradise
11Peter ToshReggae10/19/19449/11/1987Grange Hill, JamaicaKingston, JamaicaYou Can't Blame the YouthLegalize itGlass HouseMurderRastafariStepping Razor: Red X
12Stephen MarleyReggae5/19/1972Wilmington, DEMind ControlMedicationChase DemIron BarsInna Di Red
13Ziggy MarleyReggae10/17/1968Kingston, JamaicaLookingTrue to MyselfDragonflyKeep My FaithShark TaleLife and DebtI Am BoltPup StarThe Strink is In
Sheet2


Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Name"}, {
        {"Genre", each Text.Combine(_[Genre],", "), type text},
        {"Born Date", each Text.Combine(_[Born Date],", "), type text},
        {"Died Date", each Text.Combine(_[Died Date],", "), type text},
        {"Born Location", each Text.Combine(_[Born Location],", "), type text},
        {"Died Location", each Text.Combine(_[Died Location],", "), type text},
        {"Parents", each Text.Combine(_[Parents],", "), type text},
        {"Favorite Songs", each Text.Combine(_[Favorite Songs],", "), type text},
        {"Cause of death", each Text.Combine(_[Cause of death],", "), type text},
        {"Religion", each Text.Combine(_[Religion],", "), type text},
        {"Movies", each Text.Combine(_[Movies],", "), type text}
        }),
    SplitSongs = Table.SplitColumn(Group, "Favorite Songs", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), {"Favorite Songs.1", "Favorite Songs.2", "Favorite Songs.3", "Favorite Songs.4", "Favorite Songs.5"}),
    SplitMovies = Table.SplitColumn(SplitSongs, "Movies", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), {"Movies.1", "Movies.2", "Movies.3", "Movies.4", "Movies.5"})
in
    SplitMovies
 
Upvote 0
You can make it a bit shorter with count delimiter and maxcount
Rich (BB code):
SplitSongs = Table.SplitColumn(Group, "Favorite Songs", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), {"Favorite Songs.1", "Favorite Songs.2", "Favorite Songs.3", "Favorite Songs.4", "Favorite Songs.5"}),
to
Rich (BB code):
SplitSongs = Table.SplitColumn(Group, "Favorite Songs", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), MaxCount),
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

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