Concatenate with conditions

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591
Hello all,
I have a table with multiple columns where in Column A are unique values, in column D are values they are assigned to.
Would like to consolidate all the rows by merging by values in column D while values from column A are listed in one cell
Straightforward, managed that with this code
Code:
Function ConcatIf(ByVal compareRange As Range, ByVal xCriteria As Variant, Optional ByVal stringsRange As Range, _Optional Delimiter As String, Optional NoDuplicates As Boolean) As String
Dim i As Long, j As Long
With compareRange.Parent
Set compareRange = Application.Intersect(compareRange, Range(.UsedRange, .Range("a1")))
End With
If compareRange Is Nothing Then Exit Function
If stringsRange Is Nothing Then Set stringsRange = compareRange
Set stringsRange = compareRange.Offset(stringsRange.Row - compareRange.Row, _
stringsRange.Column - compareRange.Column)
For i = 1 To compareRange.Rows.Count
For j = 1 To compareRange.Columns.Count
If (Application.CountIf(compareRange.Cells(i, j), xCriteria) = 1) Then
If InStr(ConcatIf, Delimiter & CStr(stringsRange.Cells(i, j))) <> 0 Imp Not (NoDuplicates) Then
ConcatIf = ConcatIf & Delimiter & CStr(stringsRange.Cells(i, j))
End If
End If
Next j
Next i
ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1)
End Function

Couple of problems I need this to be adapted to, if possible
Problem 1. want it to stop with listing at 8 listed values and after that to continue listing in a new row
(if there is 9 unique values from column A associated with value from column D it should be in one row 8A -D and then row below 1A -D
Problem 2: Would be nice that all of this is fitted in a single code which can be run when needed, at the end it should look something like:
(working on a Sheet2)
Code:
Sub Concatenate()
1. messagebox to select working range of master table (sheet1)
2. find last used range on sheet2
3. in column D list values from column D in a master table, but remove duplicates
4. in column E do the concatenate function from column A in a master table
5. in column A would be filled formula which I think I can sort it out
6. in column B would be filed formula which I think I can sort it out
7. column C is irrelevant and can be used as helper column if needed
8. in column F I need another example of concatenate, this time from column F in master table with sumif in bracket
9. repeat steps 2 to 8 but this time source is column H in master table
Hope it makes sense, I can post some data and examples how it should look like, until your response will continue to work hard on Google :)
Thanks
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Maybe just concatenate part then.. in column b are numbers, in column D fruit names. put on a new sheet in column B fruit name and in column C in one row all the numbers assigned to them, but max 8 per cell, then in moves next row
ex.
1 apple
2 apple
3 banana
4 apple
5 apple
6 apple
7 apple
8 apple
9 apple
10 apple
11 banana
turns to
apple 1 2 4 5 6 7 8 9
apple 10
banana 3

Thanks
(any feedback (even negative one) is better than seen:ROFLMAO:)
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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