Sub test()
Dim DataRng As Range
Dim i As Integer, j As Integer, k1 As Integer, k_final As Integer
Dim LstCol As Integer, LR As Integer
Dim Mytext As String
Set WSF = Application.WorksheetFunction
Set DataRng = Sheets("First sheet").Range("A1:K10")
LstCol = 11
LR = 4
For i = 2 To LstCol
If Sheets("Final").Cells(1, i) = "Aligned" Or Sheets("Final").Cells(1, i) = "Global" Then
Mytext = ""
For j = 2 To LR
k1 = WSF.Match(Sheets("Final").Cells(j, 1), WSF.Index(DataRng, 0, 1), 0)
k_final = k1 + WSF.CountIf(WSF.Index(DataRng, 0, 1), Sheets("Final").Cells(j, 1)) - 1
' Mytext = WSF.TextJoin("," & Chr(10), True, Sheets("First sheet").Range(Cells(k1, i) & ":" & Cells(k_final, i)))
' Mytext = WSF.TextJoin("," & Chr(10), True, Sheets("First sheet").Range(Cells(k1, i), Cells(k_final, i)))
Mytext = WSF.TextJoin("," & Chr(10), True, WSF.Index(DataRng, k1, i) & ":" & WSF.Index(DataRng, k_final, i))
Sheets("Final").Cells(j, i) = Mytext
Next j
Else
For j = 2 To LR
Sheets("Final").Cells(j, i).Value = WSF.Index(DataRng, WSF.Match(Sheets("Final").Cells(j, 1), WSF.Index(DataRng, 0, 1), 0), i)
Next j
End If
Next i
End Sub
Bookmarks