Converting Data to Filterable format.

awat17

New Member
Joined
Sep 28, 2017
Messages
1
I have a spreadsheet that is not in a usable format and need help rearranging it.

It is currently formatted like the table below but with over 300 Kids and 20 clubs. This format has a lot of empty cells and its not easy to filter.

NameClub1Club2Club3Club4Club5
Kid1Choice 1Choice2
Kid2Choice 1Choice2
Kid3Choice 2Choice 1
Kid4Choice 2Choice 1

<tbody>
</tbody>


I would like my table to look like this:
NameChoice 1Choice 2Choice 3
Kid 1Club 1Club 2Club3
Kid 2Club 4Club 6Club 1
Kid 3Club 8Club 2Club 7
Kid 4Club 1Club 3Club 8

<tbody>
</tbody>


Any help would be appreciated.

Thanks!
 

Zubair Muhammad

Board Regular
Joined
Sep 14, 2017
Messages
52
Assuming Current Format is in Sheet1 from cells A1 to U 301 i.e. 300 Kids and 20 clubs

And you create the new format in a New Sheet starting from A1 with Choices in first row and kid names in first column.

Enter this formula in cell B2 in new sheet and drag to get the club names

=IFERROR(INDEX(Sheet1!$B$1:$U$1,,MATCH(B$1,OFFSET(Sheet1!$B$1:$U$1,MATCH($A2,Sheet1!$A$2:$A$301,0),,),0)),"")
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
42,224
Office Version
365
Platform
Windows
Welcome to the MrExcel board!

Your sample result doesn't seem to relate to your sample data, and you didn't say where you wanted the results, but see if this macro helps.
It puts the results off to the right of the original data.
Test in a copy of your workbook.

Code:
Sub Rearrange()
  Dim d As Object
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long
  Dim s As String
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  d(0) = Empty
  With Range("A1").CurrentRegion
    a = .Value
    ReDim b(1 To UBound(a), 1 To 1)
    b(1, 1) = a(1, 1)
    For i = 2 To UBound(a, 1)
      b(i, 1) = a(i, 1)
      For j = 2 To UBound(a, 2)
        s = a(i, j)
        If Len(s) > 0 Then
          If Not d.exists(s) Then
            d(s) = d.Count + 1
            ReDim Preserve b(1 To UBound(b), 1 To d.Count)
            b(1, d.Count) = s
          End If
          b(i, d(s)) = a(1, j)
        End If
      Next j
    Next i
    .Offset(, .Columns.Count + 1).Resize(UBound(b, 1), UBound(b, 2)).Value = b
  End With
End Sub
The code above produced the results shown in columns H:J from the original data shown in A:F.

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th><th>H</th><th>I</th><th>J</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">1</td><td style=";">Name</td><td style=";">Club1</td><td style=";">Club2</td><td style=";">Club3</td><td style=";">Club4</td><td style=";">Club5</td><td style="text-align: right;;"></td><td style=";">Name</td><td style=";">Choice 1</td><td style=";">Choice 2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">2</td><td style=";">Kid1</td><td style="text-align: right;;"></td><td style=";">Choice 1</td><td style="text-align: right;;"></td><td style=";">Choice 2</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">Kid1</td><td style=";">Club2</td><td style=";">Club4</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">3</td><td style=";">Kid2</td><td style=";">Choice 1</td><td style="text-align: right;;"></td><td style=";">Choice 2</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">Kid2</td><td style=";">Club1</td><td style=";">Club3</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style=";">Kid3</td><td style=";">Choice 2</td><td style=";">Choice 1</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">Kid3</td><td style=";">Club2</td><td style=";">Club1</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">5</td><td style=";">Kid4</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">Choice 2</td><td style="text-align: right;;"></td><td style=";">Choice 1</td><td style="text-align: right;;"></td><td style=";">Kid4</td><td style=";">Club5</td><td style=";">Club3</td></tr></tbody></table><p style="width:7.2em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Rearrange</p><br /><br />
 
Last edited:

Forum statistics

Threads
1,081,726
Messages
5,360,906
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top