Concatenate if it matches criteria

ORoxo

Board Regular
Joined
Oct 30, 2016
Messages
149
Hello, everyone,
I'm trying to concatenate several cells into one if it matches a certain criterias. I was wondering if you could lay me a hand. Below you will find a file with a simple example:

https://ufile.io/9e7ht

Thanks!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I'm guessing you want to actually move all the info in a cell rather than just displaying it

If a display will work you could use in A5 =IF(A=1,A2&" "&A3&" "&A4,"")
 
Upvote 0
How about
Code:
Sub MyConcat()
   Dim Cl As Range
   Dim Ws As Worksheet
   
   Set Ws = Sheets("Input")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws.Range("B1", Ws.Range("B" & Rows.Count).End(xlUp))
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Cl.Offset(, -1).Value
         Else
            .Item(Cl.Value) = .Item(Cl.Value) & ", " & Cl.Offset(, -1).Value
         End If
      Next Cl
      Sheets("Output").Range("B1").Resize(.Count).Value = Application.Transpose(.Keys)
      Sheets("Output").Range("A1").Resize(.Count).Value = Application.Transpose(.Items)
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,043
Messages
6,128,470
Members
449,455
Latest member
jesski

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