Replacement for TEXTJOIN as using Excel 2016 and need to combine data

BradleyS

Active Member
Joined
Oct 28, 2006
Messages
351
Office Version
  1. 2010
Platform
  1. Windows
I have a formula using TEXTJOIN that works great, but the PC I need to run it on only has Excel 2016, so it doesn't work, so I'm looking for an alternative method to achieve the same result using a formula or VBA code.

I just need to combine all the data in column B unique to each ID and show it in column C. I know it repeats for each ID, but that's OK as I'm only going to use the first one of each id anyway using a VLOOKUP.

Cell Formulas
RangeFormula
C2:C7C2=TEXTJOIN(CHAR(10),TRUE,IF(A2=$A$2:$A$7,$B$2:$B$7,""))
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Can try using CONCAT which is still in use
 
Upvote 0
In the end I came up with this. I hope it helps someone else.

VBA Code:
Private Sub CombineData()
   
    'Get active worksheet name
    Dim sName As String
        sName = ActiveSheet.Name
     
    Const dFirstCellAddress As String = "I2"
   
    ' Source range to an array.
   
    Dim Data As Variant
    Dim rCount As Long
   
    With ThisWorkbook.Worksheets(sName).Range("A1").CurrentRegion
        rCount = .Rows.Count - 1
        If rCount < 1 Then Exit Sub ' no data or only headers
        Data = .Resize(rCount, 7).Offset(1).Value
    End With
   
    ' Array to a dictionary of dictionaries.
   
    Dim dict As Object: Set dict = CreateObject("Scripting.Dictionary")
    dict.CompareMode = vbTextCompare
   
    Dim Key As Variant
    Dim Item As Variant
    Dim r As Long
    Dim n As Long
   
    For r = 1 To rCount
        Item = CStr(Data(r, 7))
        If Not IsError(Item) Then
            If Len(Item) > 0 Then
                Key = Data(r, 1)
                If Not IsError(Key) Then
                    If Len(Key) > 0 Then
                        If Not dict.Exists(Key) Then
                            Set dict(Key) = CreateObject("Scripting.Dictionary")
                        End If
                        For n = 0 To 7
                            dict(Key)(Item) = Empty
                        Next n
                    End If
                End If
            End If
        End If
    Next r

    rCount = dict.Count
    If rCount = 0 Then Exit Sub ' only error values or blanks
    
    ' Dictionary of dictionaries to the array.
   
    ReDim Data(1 To rCount, 1 To 2)
    r = 0
   
    For Each Key In dict.Keys
        r = r + 1
        Data(r, 1) = Key
        Data(r, 2) = Join(dict(Key).Keys, vbNewLine)
    Next Key
   
    ' Array to the destination range.
   
    With ThisWorkbook.Worksheets(sName).Range(dFirstCellAddress).Resize(, 2)
        .Resize(rCount).Value = Data
        .Resize(.Worksheet.Rows.Count - .Row - rCount + 1).Offset(rCount).Clear
    End With

    'MsgBox "Data combined.", vbInformation

End Sub
 
Upvote 0
Solution
Glad you sorted it & thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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