View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Concatenate without duplicates

On Thu, 1 Oct 2009 18:52:01 -0700, QB wrote:

I have a table with cols A through J. I need to place in col J a
concatenation of Cols B through I, but without duplication as the same entry
could appear in multiple cols.

How can this be done?

Thank you,

QB


In view of Jacob's critique that the duplicates are considered to exist if one
is contained in another, (so that "range" is considered a duplicate since it is
contained within "Orange"), the following removes that:

=========================
Option Explicit
Function ConcatNonDups(rg) As String
'Adds a line feed and no dups or blanks
Dim cCol As Collection
Dim c As Range
For Each c In rg
If c.Text < 0 And _
WorksheetFunction.CountIf(rg, c.Text) = 1 Then
ConcatNonDups = ConcatNonDups & c.Text & vbLf 'edit to suit
End If
Next c
ConcatNonDups = Left(ConcatNonDups, Len(ConcatNonDups) - 1)
End Function
=============================


Jacob's other critique is irrelevant since it is the last, and not the first,
character that needs to be removed.
--ron