
Originally Posted by
ed_han
.....Constraints:
I am unable to use Morefunc.
I am not proficient in VBA.
Does anyone have any thoughts?
You don't have to be proficient in VBA to use this User Defined Function. Copy and paste it into a module in the VBA editor. It is called Concatall. It was written by tigeravatar and shows up frequently on the Forum.
'tigeravatar ExcelForum
Public Function ConcatAll(ByVal varData As Variant, Optional ByVal sDelimiter As String = vbNullString, Optional ByVal bUnique As Boolean = False) As String
'Created by TigerAvatar at www.excelforum.com, September 2012
'Purpose is to concatenate many strings into a single string
'Can be used with arrays, range objects, and collections
Dim DataIndex As Variant 'Used to loop through arrays, range objects, and collections
Dim strResult As String 'Used to build the result string
'Test if varData is an Array, Range, or Collection
If IsArray(varData) _
Or TypeOf varData Is Range _
Or TypeOf varData Is Collection Then
'Found to be an, array, range object, or collection
'Loop through each item in varData
For Each DataIndex In varData
'Check if the item isn't empty
If Len(DataIndex) > 0 Then
'Found the item isn't empty, check if user specified bUnique as True
If bUnique = True Then
'bUnique is true, check if the item has been included in the result yet
If InStr(1, "||" & strResult & "||", "||" & DataIndex & "||", vbTextCompare) = 0 Then
'Item has not been included in the result, add item to the result
strResult = strResult & "||" & DataIndex
End If
Else
'bUnique is not true, add item to the result
strResult = strResult & "||" & DataIndex
End If
End If
Next DataIndex
'Correct strResult to remove beginning delimiter and convert "||" to the specified sDelimiter
strResult = Replace(Mid(strResult, 3), "||", sDelimiter)
Else
'Found not to be an array, range object, or collection
'Simply set the result = varData
strResult = varData
End If
'Output result
ConcatAll = strResult
End Function
This is one way to use it. This formula must be array-entered. Array enter means the formula must be committed by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
Formula:
=ConcatAll(IFERROR(IF(A2=Territory!$A$14:$A$33,Territory!$B$14:$B$33,""),""),", ")
Then fill down.
Results look like this:
Row\Col |
A |
B |
C |
2 |
Business 1 |
111 |
619, 318, 320, 615, 306, 321, 322, 330 |
3 |
Business 2 |
116 |
355, 345, 148, 139, 140 |
4 |
Business 3 |
355 |
116, 119, 118, 220, 230, 614, 615 |
Is this what you are wanting?
Edit formula change.
Bookmarks