Excel2011: Vlookup and Combine

后端 未结 1 1107
太阳男子
太阳男子 2020-11-30 15:52

I\'m having some difficulty combining several functions to do what I want in a 70000+ line excel file. ANY tips or pointers or advice greatly appreciated.

I have 2 c

相关标签:
1条回答
  • 2020-11-30 16:25

    The textjoin function can take conditions when entered as an array formula with CSE.

    =TEXTJOIN(", ", TRUE, IF(A2:INDEX(A:A,MATCH(1E+99,A:A))=C2, B2:INDEX(B:B,MATCH(1E+99,A:A)), TEXT(,)))
    

    If you do not have the newer textjoin function in your version of Excel, search this site's textjoin tag for VBA UDF and worksheet formula alternates. I've created a couple using static dict as scripting.dictionary.

    Here is some standard public module code that will collect them all using a 2-D array and a scripting dictionary.

    This sub procedure requires that you add Microsoft Scripting Runtime to the VBA project using Tools, References.

    Option Explicit
    
    Sub qwewrety()
        Dim delim As String, arr As Variant
        Dim d As Long, dict As New Scripting.dictionary
    
        delim = Chr(44) & Chr(32)
    
        With Worksheets("sheet3")
            arr = .Range(.Cells(2, "A"), .Cells(.Rows.Count, "B").End(xlUp)).Value2
    
            For d = LBound(arr, 1) To UBound(arr, 1)
                If dict.exists(arr(d, 1)) Then
                    dict.Item(arr(d, 1)) = dict.Item(arr(d, 1)) & delim & arr(d, 2)
                Else
                    dict.Item(arr(d, 1)) = arr(d, 2)
                End If
            Next d
    
            .Cells(2, "C").Resize(dict.Count) = Application.Transpose(dict.keys)
            .Cells(2, "D").Resize(dict.Count) = Application.Transpose(dict.items)
    
        End With
    End Sub
    
    0 讨论(0)
提交回复
热议问题