Pick up multiple results as text join and dynamic array range

fornight2024

New Member
Joined
Dec 5, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi, I have uploaded here a sample.

I need to put in a formula similar to vlookup based on account but it needs to show all results. vlookup only shows the first results that appear.

I searched and found an answer with a formula that I do not really understand. The formula that I found was:

IFERROR(TEXTJOIN(", ",,FILTER(INDEX("namedrange",,2),INDEX("namedrange",,1)=OFFSET("cell",0,-2))),"")

I don't quite understand the last bit "Offset(cell,0,-2) and unable to apply to my case here. In addition, I don't see any "lookup" based on the account as reference.
 

Attachments

  • 2025-01-07 09_33_19-excel example - Excel.jpg
    2025-01-07 09_33_19-excel example - Excel.jpg
    30 KB · Views: 10

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here is a UDF from several years ago
VBA Code:
Function MLOOKUP(ByRef TableArray As Range, ByVal LookupVal, ByRef LookupRange As Range, _
                                                        Optional ByVal NthMatch As Long)

' Author        : Krishnakumar @ ExcelFox.com


If Not TypeOf TableArray Is Range Then
    MLOOKUP = CVErr(2042)
    Exit Function
End If
If Not TypeOf LookupRange Is Range Then
    MLOOKUP = CVErr(2042)
    Exit Function
End If
If TableArray.Rows.Count <> LookupRange.Rows.Count Then
    MLOOKUP = CVErr(2042)
    Exit Function
End If
If TableArray.Columns.Count <> LookupRange.Columns.Count Then
    MLOOKUP = CVErr(2042)
    Exit Function
End If

Dim LV_Cnt      As Long 'Count Loookup Value
Dim KA1, KA2
Dim r As Long, c As Long
Dim fFoundNo    As Long
Dim n           As Long
Dim strLval     As String

If IsNumeric(LookupVal) Then
    LV_Cnt = Evaluate("countif(" & LookupRange.Address & "," & LookupVal & ")")
    fFoundNo = Evaluate("match(" & CLng(LookupVal) & "," & LookupRange.Address & ",0)")
ElseIf IsDate(LookupVal) Then
    LV_Cnt = Evaluate("countif(" & LookupRange.Address & "," & CLng(LookupVal) & ")")
    fFoundNo = Evaluate("match(" & CLng(LookupVal) & "," & LookupRange.Address & ",0)")
Else
    strLval = """" & LookupVal & """"
    LV_Cnt = Evaluate("countif(" & LookupRange.Address & "," & strLval & ")")
    fFoundNo = Evaluate("match(" & strLval & "," & LookupRange.Address & ",0)")
End If

If NthMatch > 0 Then
    If LV_Cnt = 0 Or NthMatch > LV_Cnt Then
        MLOOKUP = CVErr(2042)
        Exit Function
    End If
End If


KA1 = TableArray: KA2 = LookupRange

For r = fFoundNo To UBound(KA1, 1)
    For c = 1 To UBound(KA1, 2)
        If LCase$(KA2(r, c)) = LCase$(LookupVal) Then
            If NthMatch Then
                n = n + 1
                If n = NthMatch Then
                    MLOOKUP = KA1(r, c)
                    Exit Function
                End If
            Else
                MLOOKUP = MLOOKUP & "," & KA1(r, c)
            End If
        End If
    Next
Next
MLOOKUP = Mid$(MLOOKUP, 2)
End Function


Syntax
MLOOKUP(TableArray,LookupValue,LookupRange,[NthMatch])
If the optional NthMatch is missing, All the values will be concatenated in a single cell
 
Upvote 0
Hello, if you have access to GROUPBY function you could try:

Excel Formula:
=CHOOSECOLS(GROUPBY(G2:G7,H2:H7,ARRAYTOTEXT,,0),2)
 
Upvote 0
Is this what you are after?

25 01 07.xlsm
BDEFGH
1AccountReferenceAccountText
210100Note 1, Note 2, Note 610100Note 1
310200Note 310100Note 2
410300Note 410200Note 3
514500Note 510300Note 4
614500Note 5
710100Note 6
All results
Cell Formulas
RangeFormula
D2:D5D2=TEXTJOIN(", ",,FILTER(H$2:H$7,G$2:G$7=B2,""))
 
Upvote 0
Solution
Is this what you are after?

25 01 07.xlsm
BDEFGH
1AccountReferenceAccountText
210100Note 1, Note 2, Note 610100Note 1
310200Note 310100Note 2
410300Note 410200Note 3
514500Note 510300Note 4
614500Note 5
710100Note 6
All results
Cell Formulas
RangeFormula
D2:D5D2=TEXTJOIN(", ",,FILTER(H$2:H$7,G$2:G$7=B2,""))
Thank you!!!!!

This is so much easier to understand than the answer I found in my original post!
 
Upvote 0
You are welcome. Thanks for the follow-up. :)

You may prefer the above simpler formula - which needs to be copied down ..
.. or you could use this slightly more complex one (similar logic in it though) - which does not need to be copied down at all.

25 01 07.xlsm
BDEFGH
1AccountReferenceAccountText
210100Note 1, Note 2, Note 610100Note 1
310200Note 310100Note 2
410300Note 410200Note 3
514500Note 510300Note 4
614500Note 5
710100Note 6
All results (2)
Cell Formulas
RangeFormula
D2:D5D2=BYROW(B2:B5,LAMBDA(r,TEXTJOIN(", ",,FILTER(H2:H7,G2:G7=r))))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,225,481
Messages
6,185,234
Members
453,283
Latest member
Shortm88

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