macro to combine data in columns that belong to the same account

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I hope you can help,
I have two lots of data
Sheet "Raw" contains the raw data we download from our system.
Sheet "Single" has a list of all the unique account numbers from that download.

Now sheet raw contains the ID in column "A" and the data I need in column Z
what I need is in sheet "Single" to look down "RAW" column a and every time we find the ID in column A combine the data into column "Z" using "," to separate and ignoring blanks

So example of sheet raw
AZ
1IDDataNote: this is what i currently have
212345Hello
312345Combine
412345This
554321and
654321this
7777Exclude blank
8777
9777Cells

and what id like in "Single" sheet
AZ
1IDDAtathis is what i want
212345Hello,Combine,This
354321and,this
4777Exclude blank,cells

I hope thats clear, please help if you can thanks
Tony
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This will do work if you don't have too much data:
VBA Code:
Sub test()
  Dim lRow As Long
  lRow = Cells(Rows.Count, 1).End(xlUp).Row
  Application.ScreenUpdating = False
  For i = lRow To 3 Step -1
    If Cells(i, 1).Value = Cells(i - 1, 1).Value Then
      If Not Cells(i, 26).Value = "" Then
          Cells(i - 1, 26).Value = Cells(i - 1, 26).Value & ", " & Cells(i, 26).Value
      End If
      Rows(i).EntireRow.Delete
    End If
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,224
Members
453,025
Latest member
Hannah_Pham93

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