Moving Data From Columns To Rows

mlmrob

Board Regular
Joined
Sep 22, 2008
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon guys,

Each day I download a list of racehorses with the distances they have been beaten in each of their last 10 races or less.

The data downloads as all in Column A horse name and column b as didtance beaten

Horse A 6
Horse A 10
Horse A
Horse A 5
Horse B 3
Horse B 5
Horse B 1
Horse B 10
Horse C 0.5
Horse C
Horse C 6
Horse C 2

Where there is a gap it means the horse won or didn't finish the race.

What I want to do is display the data all in the same row across the columns

Horse A 6, 10, , 5
Horse B 3, 5, 1, 10

and so on

I have attached a ink from One Drive from one drive for a visual.


1706444225605.png
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try. Select suitable.
Formula1
Excel Formula:
=LET(a,UNIQUE(A2:A13),b,TEXTSPLIT(TEXTJOIN(",",TRUE,BYROW(a,LAMBDA(ro,TEXTJOIN(";",TRUE,IF((A2:A13=ro)*(B2:B13<>""),B2:B13,""))))),";",",",TRUE),HSTACK(a,IFERROR(b,"")))
Or Formula2
Excel Formula:
=LET(a,UNIQUE(A2:A13),b,BYROW(a,LAMBDA(ro,TEXTJOIN(",",TRUE,IF((A2:A13=ro)*(B2:B13<>""),B2:B13,"")))),HSTACK(a,b))
 
Upvote 0
Another option
Excel Formula:
=LET(u,UNIQUE(FILTER(A1:A200,A1:A200<>"")),m,MAX(COUNTIFS(A:A,u)),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,EXPAND(TOROW(FILTER(B1:B200,A1:A200=y)),,m,""))))),1))
 
Upvote 0
Solution
VBA option:
VBA Code:
Sub TransposeData()
    Application.ScreenUpdating = False
    Dim r As Long, c As Long, v As Variant, arr() As Variant, dic As Object, x As Long, lRow As Long, cnt As Long, y As Long: y = 1
    lRow = Range("A" & Rows.Count).End(xlUp).Row
    v = Range("A1:A" & lRow).Resize(, 2).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
        End If
    Next i
    cnt = dic.Count
    For i = LBound(v) To UBound(v)
        If i = lRow Then
            x = x + 1
            ReDim Preserve arr(1 To x)
            arr(x) = v(i, 2)
            Range("G" & y).Resize(, x).Value = arr
        Else
            If v(i, 1) = v(i + 1, 1) Then
                x = x + 1
                ReDim Preserve arr(1 To x)
                arr(x) = v(i, 2)
            Else
                x = x + 1
                ReDim Preserve arr(1 To x)
                arr(x) = v(i, 2)
                Range("G" & y).Resize(, x).Value = arr
                x = 0
                y = y + 1
            End If
        End If
    Next i
    Range("F1").Resize(cnt) = Application.Transpose(dic.keys)
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Wow, such prompt replies. Thank you guys. Will try those out.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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