Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 2
Default if row has duplicates, concat entries in another column?

I'm new to Excel, and struggling with compiling multiple duplicate rows, example:

col1 col2
Mark Robbery
Mark Murder
Mark Arson
John Assault
John DUI
Dan Murder

The result I want is:
col1 col3
Mark Robbery, Murder, Arson
John Assault, DUI
Dan Murder

Any help would be appreciated!

Last edited by rchun : May 14th 13 at 09:21 PM Reason: clarification
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,872
Default if row has duplicates, concat entries in another column?

Hi,

Am Tue, 14 May 2013 21:20:25 +0100 schrieb rchun:

col1 col2
Mark Robbery
Mark Murder
Mark Arson
John Assault
John DUI
Dan Murder

The result I want is:
col1 col3
Mark Robbery, Murder, Arson
John Assault, DUI
Dan Murder


try it with a macro. Press Alt+F11 = Insert = Module and paste the
code in the code window:

Sub Test()
Dim LRow1 As Long
Dim LRow2 As Long
Dim i As Long
Dim j As Long
Dim rngC As Range
Dim c As Range
Dim firstAddress As String
Dim myStr As String

j = 1
LRow1 = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LRow1
If WorksheetFunction.CountIf(Range(Cells(1, 1), _
Cells(i, 1)), Cells(i, 1)) = 1 Then
Cells(j, 3) = Cells(i, 1)
j = j + 1
End If
Next

LRow2 = Cells(Rows.Count, 3).End(xlUp).Row
For Each rngC In Range("C1:C" & LRow2)
myStr = ""
With Range("A1:A" & LRow1)
Set c = .Find(rngC, after:=Cells(LRow1, 1), LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
myStr = myStr & c.Offset(0, 1) & ", "
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
rngC.Offset(0, 1) = Left(myStr, Len(myStr) - 2)
End If
End With
Next
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Junior Member
 
Posts: 2
Default

awesome, thank you! that's pretty complicated, but it worked!

Quote:
Originally Posted by Claus Busch View Post
Hi,

Am Tue, 14 May 2013 21:20:25 +0100 schrieb rchun:

col1 col2
Mark Robbery
Mark Murder
Mark Arson
John Assault
John DUI
Dan Murder

The result I want is:
col1 col3
Mark Robbery, Murder, Arson
John Assault, DUI
Dan Murder


try it with a macro. Press Alt+F11 = Insert = Module and paste the
code in the code window:

Sub Test()
Dim LRow1 As Long
Dim LRow2 As Long
Dim i As Long
Dim j As Long
Dim rngC As Range
Dim c As Range
Dim firstAddress As String
Dim myStr As String

j = 1
LRow1 = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LRow1
If WorksheetFunction.CountIf(Range(Cells(1, 1), _
Cells(i, 1)), Cells(i, 1)) = 1 Then
Cells(j, 3) = Cells(i, 1)
j = j + 1
End If
Next

LRow2 = Cells(Rows.Count, 3).End(xlUp).Row
For Each rngC In Range("C1:C" & LRow2)
myStr = ""
With Range("A1:A" & LRow1)
Set c = .Find(rngC, after:=Cells(LRow1, 1), LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
myStr = myStr & c.Offset(0, 1) & ", "
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
rngC.Offset(0, 1) = Left(myStr, Len(myStr) - 2)
End If
End With
Next
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default if row has duplicates, concat entries in another column?

Whoever wrote this macro just saved my life :D
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default if row has duplicates, concat entries in another column?

On Tuesday, May 14, 2013 4:20:25 PM UTC-4, rchun wrote:
I'm new to Excel, and struggling with compiling multiple duplicate rows,

example:



col1 col2

Mark Robbery

Mark Murder

Mark Arson

John Assault

John DUI

Dan Murder



The result I want is:

col1 col3

Mark Robbery, Murder, Arson

John Assault, DUI

Dan Murder



Any help would be appreciated!









--

rchun


The Merge Assistant, http://www.add-ins.com/product_list.htm will do exactly what you want done
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
list of entries from a column without duplicates rpick60 Excel Worksheet Functions 5 December 10th 07 12:27 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM
Concat values in two or more rows based on id and eliminate duplicates italia Excel Programming 2 October 19th 05 06:33 PM
Summing duplicate entries and non duplicates Big H Excel Programming 13 September 18th 05 12:01 AM
Copy multiple entries and paste without duplicates ExcelMonkey[_116_] Excel Programming 2 May 13th 04 09:45 PM


All times are GMT +1. The time now is 09:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"