PC Review


Reply
Thread Tools Rate Thread

Compare cells and concatenate on match

 
 
vs88@yahoo.com
Guest
Posts: n/a
 
      18th Dec 2006
I need to compare rows in a table, and concatenate data in col D
wherever there's a match to previous rows in cols A:C. The number of
rows where matches may occur is variable. After the data is
concatenated, the extraneous matching rows must be deleted.

A B C D
Europe Germany Name1 Frankfurt
Europe Germany Name1 Munich
Europe Germany Name1 Bonn
Europe Germany Name1 Dusseldorf
Europe France Name2 Paris
North America United States Name3 Chicago
North America United States Name4 Seattle
Europe United Kingdom Name4 London
Asia Japan Name5 Tokyo
Asia Japan Name5 Osaka
Asia Japan Name5 Kyoto

Desire output as follows:

A B C D
Europe Germany Name1 Frankfurt, Munich, Bonn, Dusseldorf
Europe France Name2 Paris
North America United States Name3 Chicago
North America United States Name4 Seattle
Europe United Kingdom Name4 London
Asia Japan Name5 Tokyo, Osaka, Kyoto

I can do part of what I need with this IF statement:
=IF(A3=A2,IF(B3=B2,IF(C3=C2,CONCATENATE(D3&", "&D2),D2)))

I can't figure out how to address more than 2 rows that match or how
to delete the extra rows. I have made numerous attempts but am stumped.
Will this need to be done via VBA? If you can point me to any relevant
resources for a coding jump-start, that'd be great. Thanks for any
inspiration on this!

 
Reply With Quote
 
 
 
 
vs88@yahoo.com
Guest
Posts: n/a
 
      19th Dec 2006
This did the trick beautifully. Thank you so much!

 
Reply With Quote
 
Dan R.
Guest
Posts: n/a
 
      18th Jan 2007
I'm using this code of Martins with numbers instead of text and I would
like it to output ONLY the largest value in column 4, instead of a
concatenation of all the values. I'm sure it's simple but I can't seem
to figure it out.

Thanks,
-- Dan

Martin Fishlock wrote:
> Hi,
>
> Try this:
>
> Option Explicit
>
> Sub concat()
>
> Dim lRowFirst As Long
> Dim lRowLast As Long
> Dim lRow As Long
> lRowFirst = ActiveCell.CurrentRegion.Row + 1 '
> lRowLast = ActiveCell.CurrentRegion.Rows.Count + lRowFirst - 2
>
> For lRow = lRowLast To lRowFirst Step -1
> If Cells(lRow, 1) = Cells(lRow - 1, 1) And _
> Cells(lRow, 2) = Cells(lRow - 1, 2) And _
> Cells(lRow, 3) = Cells(lRow - 1, 3) Then
> Cells(lRow - 1, 4) = Cells(lRow - 1, 4) _
> & ", " & Cells(lRow, 4)
> Rows(lRow).Delete
> End If
> Next lRow
>
> End Sub
>
> --
> Hope this helps
> Martin Fishlock
> Please do not forget to rate this reply.
>
>
> "(E-Mail Removed)" wrote:
>
> > I need to compare rows in a table, and concatenate data in col D
> > wherever there's a match to previous rows in cols A:C. The number of
> > rows where matches may occur is variable. After the data is
> > concatenated, the extraneous matching rows must be deleted.
> >
> > A B C D
> > Europe Germany Name1 Frankfurt
> > Europe Germany Name1 Munich
> > Europe Germany Name1 Bonn
> > Europe Germany Name1 Dusseldorf
> > Europe France Name2 Paris
> > North America United States Name3 Chicago
> > North America United States Name4 Seattle
> > Europe United Kingdom Name4 London
> > Asia Japan Name5 Tokyo
> > Asia Japan Name5 Osaka
> > Asia Japan Name5 Kyoto
> >
> > Desire output as follows:
> >
> > A B C D
> > Europe Germany Name1 Frankfurt, Munich, Bonn, Dusseldorf
> > Europe France Name2 Paris
> > North America United States Name3 Chicago
> > North America United States Name4 Seattle
> > Europe United Kingdom Name4 London
> > Asia Japan Name5 Tokyo, Osaka, Kyoto
> >
> > I can do part of what I need with this IF statement:
> > =IF(A3=A2,IF(B3=B2,IF(C3=C2,CONCATENATE(D3&", "&D2),D2)))
> >
> > I can't figure out how to address more than 2 rows that match or how
> > to delete the extra rows. I have made numerous attempts but am stumped.
> > Will this need to be done via VBA? If you can point me to any relevant
> > resources for a coding jump-start, that'd be great. Thanks for any
> > inspiration on this!
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare cells and copy columns after match Kcope8302 Microsoft Excel Worksheet Functions 2 5th Aug 2009 05:37 PM
Concatenate 3 cells info into 1, using MATCH and "IF" condition JMALTO Microsoft Excel Worksheet Functions 0 13th Jan 2009 11:13 PM
Compare several cells in row & output value for match Hannes Microsoft Excel Programming 0 14th Sep 2008 03:29 PM
Open two worksheets, then match and compare cells Bob Microsoft Excel Programming 0 8th Aug 2006 10:21 PM
match/compare cell with cells in a column =?Utf-8?B?UmFkdQ==?= Microsoft Excel Misc 1 13th Oct 2004 04:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:33 PM.