need macro help to concatenate columns based on criteria

Gogleguy

New Member
Joined
Feb 8, 2023
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Dear All,

Need help to create a macro which will give me the output as given in Column I (Output). Column C, D, E, F needs to be concatenated and then the macro needs to provide data for each "Supervisor Email" together in a single cell in Column I. The number of rows in the data keep changing so the macro needs to find till the last supervisor email in Column A. Please help

A​
B​
C​
D​
E​
F​
G​
H​
I​
Supervisor EmailSupervisor First NameUser Preferred LanguageUser Full NameUser Email AddressUser Overdue CountUser overdueSupervisor Overdue
Output (tab between values)​
random.name10@gogle.comRandom name10English (English)random name1random.name1@gogle.comRead/Complete128random name1 random.name1@gogle.com Read/Complete 1
random.name11@gogle.comRandom name11English (English)random name2random.name2@gogle.comRead/Complete40random name2 random.name2@gogle.com Read/Complete 4
random name3 random.name3@gogle.com Read/Complete 2
random name3random.name3@gogle.comRead/Complete20
random.name12@gogle.comRandom name12English (English)random name4random.name4@gogle.comRead/Complete82random name4 random.name4@gogle.com Read/Complete 8
random name5 random.name5@gogle.com Approval 7
random name6 random.name6@gogle.com Read/Complete 5
random name7 random.name7@gogle.com Approval 6
random name5random.name5@gogle.comApproval70
random name6random.name6@gogle.comRead/Complete50
random name7random.name7@gogle.comApproval60
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to the Forum.

Give this a try:

VBA Code:
Sub ConcatenateUserInfo_v02()

    Dim sht As Worksheet
    Dim rowLast As Long
    Dim rng As Range
    Dim arr As Variant
    Dim rowSuper As Long, rowSuperPrev As Long
    Dim outString As String
    Dim i As Long
   
   
    Set sht = ActiveSheet
    With sht
        rowLast = .Range("D" & Rows.Count).End(xlUp).Row
        Set rng = .Range(.Cells(2, "A"), .Cells(rowLast + 1, "I"))  ' Add 1 blank row to simplify logic
        arr = rng.Value
    End With

    For i = 1 To UBound(arr)
        If arr(i, 1) <> "" Or i = UBound(arr) Then
            rowSuperPrev = rowSuper
            If rowSuperPrev <> 0 Then
                arr(rowSuperPrev, 9) = Left(outString, Len(outString) - 1)
                If i = UBound(arr) Then Exit For
            End If
            rowSuper = i
            outString = ""
        End If
        outString = outString & _
                            arr(i, 4) & " " & _
                            arr(i, 5) & " " & _
                            arr(i, 6) & " " & _
                            arr(i, 7) & Chr(10)
   
    Next i
   
    With rng.Columns(9)
        .Value = Application.Index(arr, 0, 9)
        .WrapText = True
    End With
   
    rng.EntireRow.AutoFit

End Sub
 
Upvote 0
Solution
Welcome to the Forum.

Give this a try:

VBA Code:
Sub ConcatenateUserInfo_v02()

    Dim sht As Worksheet
    Dim rowLast As Long
    Dim rng As Range
    Dim arr As Variant
    Dim rowSuper As Long, rowSuperPrev As Long
    Dim outString As String
    Dim i As Long
  
  
    Set sht = ActiveSheet
    With sht
        rowLast = .Range("D" & Rows.Count).End(xlUp).Row
        Set rng = .Range(.Cells(2, "A"), .Cells(rowLast + 1, "I"))  ' Add 1 blank row to simplify logic
        arr = rng.Value
    End With

    For i = 1 To UBound(arr)
        If arr(i, 1) <> "" Or i = UBound(arr) Then
            rowSuperPrev = rowSuper
            If rowSuperPrev <> 0 Then
                arr(rowSuperPrev, 9) = Left(outString, Len(outString) - 1)
                If i = UBound(arr) Then Exit For
            End If
            rowSuper = i
            outString = ""
        End If
        outString = outString & _
                            arr(i, 4) & " " & _
                            arr(i, 5) & " " & _
                            arr(i, 6) & " " & _
                            arr(i, 7) & Chr(10)
  
    Next i
  
    With rng.Columns(9)
        .Value = Application.Index(arr, 0, 9)
        .WrapText = True
    End With
  
    rng.EntireRow.AutoFit

End Sub

This works perfect. Thank you so much Alex. Really appreciate your help.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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