Concatenate Multiple Cells with Array Formula

mgirvin

Well-known Member
Joined
Dec 15, 2005
Messages
1,245
Office Version
  1. 365
Platform
  1. Windows
Dear Smartest Excelers In The World,

If I have the following data set in cells A1:C9:

ID Comment First Unique
109876 Low Oil TRUE
109876 Checked On 12/12 FALSE
109877 Checked on 12/15 TRUE
109878 Correct Level TRUE
109877 Correct Level FALSE
109878 Perfect FALSE
109877 New FALSE
109878 Correct Level FALSE

In the First Unique column (column C) I have formulas. In C2 I have this formula (and then I copied it down):

=COUNTIF(A$2:A2,A2)=1

In cell E2, I have this formula to count unique occurrences:

=SUMPRODUCT(C2:C9*1)

In cell G2 I have this formula to extract unique records (entered with Ctrl + Shift + Enter):

=IF(ROWS(G$2:G2)<=E$2,INDEX(A$2:A$9,SMALL(IF(C$2:C$9=TRUE,ROW(C$2:C$9)-ROW(C$2)+1),ROWS(G$2:G2))),"")

Now, in cell H2 I would like a formula that would concatenate all the comments from the Comments column in the data set for each unique ID.

For example, For ID # 109876, I would like the formula to yield this text string in cell H2:

“Low Oil, Checked On 12/12”

Any ideas?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I think this will do what you want. Note that if you omit the comparison symbol from the front of the number, an equal sign will be assumed.
Code:
Function JoinAll(ByVal BaseValue As Variant, ByRef Rng As Range, ByVal Delim As String)
  Dim A As Variant, I As Long
  If Rng.Columns.Count = 2 Then
    A = Rng.Value
  Else
    A = Application.Transpose(Rng.Value)
  End If
  If BaseValue Like "[!<=>]*" Then BaseValue = "=" & BaseValue
  For I = 1 To UBound(A, 1)
    If Evaluate(A(I, 1) & BaseValue) Then JoinAll = JoinAll & Delim & A(I, 2)
  Next
  JoinAll = Mid(JoinAll, Len(Delim) + 1)
End Function
Is it possible to make this function also handle text? I don't know how to identify the BaseValue variable type in VBA. For now, my solution is using 2 different functions, 1 for text, another one for numbers.
 
Upvote 0
Is it possible to make this function also handle text? I don't know how to identify the BaseValue variable type in VBA. For now, my solution is using 2 different functions, 1 for text, another one for numbers.
I do not remember this all that clearly... can you give me a small sample of values and the result you want to see for them?
 
Upvote 0
c45xQe
Here is the result I want to see. You have provided the codes that works for both case 1,2 and 3,4. The code works for case 1,2 do not work for case 3,4 and vice versa. If it's possible I would like to have one function that work for both text and number like
FM3D2iG
1,2,3,4. Sorry to put a link, I couldn't find a way to upload a file or image.

https://ibb.co/c45xQe
c45xQe
FM3D2iG
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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