Macro which can combine a list of notes into a single cell

glide2131

New Member
Joined
May 13, 2014
Messages
4
Hello,

I have a long list of records and each record has a list of notes. Some have one note and others have many lines of notes. What I need to do is combine all the notes for each record into one cell. I know how to do this manually using TextJOIN but I have thousands of records and going through each manually would take forever. I am looking for a macro that can combine all of the notes into one cell by record. Or in other words, there should be one cell with all the combined notes per record (ID in my example)I have attached a spreadsheet as an example of what I need.

Please help.

Thanks!
Combine notes - Saved_2021-04-13_18-07-41.png
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi, @glide2131
Try this:
VBA Code:
Sub a1168029a()
Dim i As Long, j As Long, k As Long
Dim va, vb, vc

n = Range("C" & Rows.Count).End(xlUp).Row
va = Range("C2:C" & n)
vb = Range("B2:B" & n)

ReDim vc(1 To UBound(va, 1), 1 To 1)

For i = 1 To UBound(va, 1)
 j = i
    Do
        i = i + 1
        If i > UBound(va, 1) Then Exit Do
    Loop While va(i, 1) = va(i - 1, 1)
    i = i - 1
    
    tx = ""
    For k = j To i
        tx = tx & vb(k, 1) & vbLf
    Next
    
    tx = Left(tx, Len(tx) - 1)
    vc(j, 1) = tx
    
Next

Range("A2").Resize(UBound(vc, 1), 1) = vc

End Sub

Book1
ABC
1COMBINENOTEID
2Cayson Roman ZaynCaysonA
3RomanA
4ZaynA
5AriAriB
6Abraham Arian DamianAbrahamM
7ArianM
8DamianM
9Marvin Erick OwenMarvinO
10ErickO
11OwenO
12Leandro Jedidiah LandynLeandroU
13JedidiahU
14LandynU
15AnsonAnsonX
Sheet1
 
Upvote 0
Another old school option ?
VBA Code:
Sub JoinTextCell()

Dim strNote As String
Dim prvID As Long, ID As Long, rowNote As Long
Dim cell As Range, rngNote As Range

Set rngNote = Range("D3", Cells(Rows.Count, "D").End(xlUp))

For Each cell In rngNote
newID:
    If prvID = 0 Then
        rowNote = cell.Row
        prvID = cell.Value2
    End If
    ID = cell.Value2
    If ID = prvID Then
        If strNote = "" Then
            strNote = cell.Offset(0, -1).Value2
        Else
            strNote = strNote & vbLf & cell.Offset(0, -1).Value2
        End If
    Else
        Range("B" & rowNote) = strNote
        prvID = 0
        strNote = ""
        GoTo newID
    End If
Next

End Sub
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

You can do that without a macro like
Excel Formula:
=IF(COUNTIFS(C$2:C2,C2)=1,TEXTJOIN(CHAR(10),,FILTER($B$2:$B$1000,$C$2:$C$1000=C2)),"")
 
Upvote 0
Solution
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Macro: Combining a list of notes into one cell
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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