Avatar of finnstone
finnstone
 asked on

combine two columns if same value

i DOCID  in column A

1111111111
44444
44444
8888888


in column AO
experience.organization.name - Behavioral
experience.organization.name - psych
experience.organization.name - Behavioral
experience.organization.name - Behavioral
 


I want to combine the values in AO where the values are the same in column A

so values would become this (only need to do it for the first one)

experience.organization.name - Behavioral
experience.organization.name - psych, experience.organization.name - Behavioral
experience.organization.name - Behavioral,
experience.organization.name - Behavioral


NOTE, it is sorted on column A , and the tricky part is some have 3 matches, other have 4, 5 , 6 etc

I WOULD ALSO need a value put in column AP so i know which rows got appended more data
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Neil Fleming

8/22/2022 - Mon
Neil Fleming

Can you post your workbook? Code to do this will be relatively simple.
finnstone

ASKER
here is some of it, 100 rows
Book1.xlsx
finnstone

ASKER
any ideas?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Neil Fleming

try this:

Click button to routine below:
Sub Combine()
Dim rSource As Range, rComp As Range, rTarget As Range

'set source for id
Set rSource = ActiveSheet.Range("a2")


'set target cell
'Set rTarget = ActiveSheet.Range("ao2")
Set rTarget = ActiveSheet.Range("ao2")

Do
'set cell to compare
Set rComp = rSource
    Do
    'move comparison cell down one row
    Set rComp = rComp.Offset(1, 0)
        If rComp = rSource Then
        'add to target cell
        rTarget = rTarget & ", " & rTarget.Offset(rComp.Row - rSource.Row, 0)
        Set rComp = rComp.Offset(-1, 0)
        'delete row where DOCID is identical
        rComp.Offset(1, 0).EntireRow.Delete
        
        End If
    'loop until blank cell
    Loop Until rComp = ""
'next source row
Set rSource = rSource.Offset(1, 0)
'loop till blank
Loop Until rSource = ""

End Sub

Open in new window

combine-columns.xlsm
finnstone

ASKER
can this be run on 20k rows? its been working for 5 minutes
finnstone

ASKER
this doesnt work!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
finnstone

ASKER
doesnt even work for the sample you provided.
Neil Fleming

Strange. I just re-downloaded, and ran it. Can you explain what it is it that is not working? (It was your sample, btw.)

I get the attached result after running the code. The result has no identical keys in column A, and all the results collated in column AO as requested.
combine-columns2.xlsm
finnstone

ASKER
thx.

USbc4852fa730f2e61


this should be

industry - Hospital Health Care; experience.organization.name - Psychiatric, industry - Hospital Health Care, headline - Behavioral, industry - Hospital Health Care; experience.organization.name - Psychiatric
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Neil Fleming

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
finnstone

ASKER
EXCELLENT

Thanks
finnstone

ASKER
amazing code
Neil Fleming

thank you. Sorry it didn't work properly first time around.. :)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.