Super Duper Concatenate Question

John Kelly

New Member
Joined
Apr 28, 2017
Messages
5
Greetings All, I hope someone can help, I have a monthly report which it delivered in Excel but I then need to change it.

Here is what I get:
A B
500234 Tom
Sarah
Joan
299355 Peter
William
Mary
John

What I need to end up with is
A B
500234 Tom, Sarah, Joan
299355 Peter, William, Mary, John


So it's a kind of a "concatenate" and "while" type statement if such thing exists. I've spent more than enough time on it and haven't gotten anywhere. The report is about 2500 records long and it's produced monthly.

Hopefully some of you might be kind enough to take a look and maybe even offer some suggestions.

Many thanks in advance
John
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Welcome to the Board!

If you post data without the image tools or code tags, all formatting/spacing is lost. So we really cannot tell what columns "Sarah", "Joan", etc are in.
Are those in column A or column B?
 
Upvote 0
Sorry the formatting messed things up a bit. Col A has the figures and Col B has the list of names. Hope this helps
 
Upvote 0
Assuming my assumption is true, this VBA code should work.
Just adjust the value of firstRow, as needed:
Code:
Sub MyConcat()

    Dim firstRow As Long
    Dim lastRow As Long
    Dim myRow As Long
    
    Application.ScreenUpdating = False
    
'   Designate first row with data
    firstRow = 1
    
'   Find last row with data in column B
    lastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Loop through all rows backwards, up to row 1
    For myRow = lastRow To (firstRow + 1) Step -1
        If Cells(myRow, "A") = "" Then
            Cells(myRow - 1, "B") = Cells(myRow - 1, "B") & "," & Cells(myRow, "B")
            Rows(myRow).Delete
        End If
    Next myRow
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Joe, Thanks a million, I'll give it a go. The answer to your question is that the data is in a pivot table and I could flatten it with or without the blanks - so I have the option to populate if I need it to.

Thanks again
 
Upvote 0
You are welcome!
Glad I was able to help.:)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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