Forum Discussion

Matt_Paz's avatar
Matt_Paz
Copper Contributor
Feb 25, 2025
Solved

Combining two columns in a table into one ordered list

Hi all

Hope you are well!

I know how to use VSTACK in order to get two columns of data into one column. However, my needs are a little more bespoke.

How would I solve this below?

Thank you!

  • =DROP(REDUCE("",UNIQUE(A1:A14),LAMBDA(u,v,VSTACK(u,v,FILTER(B1:B14,A1:A14=v)))),1)

    If you work with the latest version of Excel you can use this formula.

6 Replies

  • Matt_Paz's avatar
    Matt_Paz
    Copper Contributor

    Thanks all, many options to consider and working perfectly

  • =DROP(REDUCE("",UNIQUE(A1:A14),LAMBDA(u,v,VSTACK(u,v,FILTER(B1:B14,A1:A14=v)))),1)

    If you work with the latest version of Excel you can use this formula.

  • Matt_Paz's avatar
    Matt_Paz
    Copper Contributor

    Thank you for the contribution, this may be a full back option but my workplace is very strict on Macros. 

    Therefore the formula either LET/LAMBDA would be the preferred option if someone is able to advise

    Thanks

    Matt

  • JKPieterse's avatar
    JKPieterse
    Silver Contributor

    Nice challenge for a lambda function, but too complicated for me. Here is a VBA user-defined function that returns what you need:

    Function StackTableBy1stColumn(proj, detail)
        Dim i As Long
        Dim res As String
        Dim projData As Variant
        Dim detData As Variant
        projData = proj.Value
        detData = detail.Value
        For i = LBound(projData, 1) To UBound(projData, 1)
            If i = 1 Then
                res = projData(1, 1) & vbNewLine & detData(1, 1)
            ElseIf projData(i, 1) <> projData(i - 1, 1) Then
                res = res & vbNewLine & projData(i, 1) & vbNewLine & detData(i, 1)
            Else
                res = res & vbNewLine & detData(i, 1)
    
            End If
        Next
        StackTableBy1stColumn = Application.Transpose(Split(res, vbNewLine))
    End Function

     

Resources