Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 78
Default Concatenate With Criteria

hello

I have 5 columns that I need to concatenate IF there is a value and if the
value isnt already in the other cells i.e:

A B C D E Concatenated (should Read):
Row 1: United Kingdom France Japan United Kingdom Italy United Kingdom,
France , Japan, Italy
Row 2: USA USA USA USA
Row 3: France Singapore Italy Spain France France, Singapore, Italy, Spain,
Row 4: United Kingdom France United Kingdom United Kingdom United
Kingdom United Kingdom, France


the following formula works to a point...
=SUBSTITUTE(TRIM(CONCATENATE(A1," ",B1," ",C1," ",D1," ",E1))," ",", ")

it brings back the following for Row 4 (mentioned above)

Row 4: United, Kingdom, France, United, Kingdom, United, Kingdom, United,
Kingdom

Where I would like it to read: United Kingdom, France

Is this possible?

Many thanks
Tracey

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Concatenate With Criteria

Shane's answer should work. To clarify, you need to put the coding into the
VBA (Press Alt+F11) and paste to either the sheet you're working on, or
insert a module and paste to that. Reposted:
**********
Hi,

If I read your question correctly, you don't want to concatenate entries
that are repeats and I think that is what the current function does. In your
example UK is only concatenated once.

If that is what you really want to do then try the following custom function:

Function myConCatenate(myRange As Range) As String
I = 1
For Each cell In myRange
If I = 1 Then
myCon = cell
ElseIf cell < "" Then
For J = I - 1 To 1 Step -1
If cell < cell.Offset(0, -J) Then
OK = True
Else
OK = False
Exit For
End If
Next J
If OK = True Then
myCon = myCon & ", " & cell
End If
End If
I = I + 1
Next cell
myConCatenate = myCon
End Function

In the spreadsheet you would enter

=myConCatenate(A1:E1)

A couple of points, this only concatenates uniques, and it will work for any
number of columns.

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire
***********************
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Tracey" wrote:

hello

I have 5 columns that I need to concatenate IF there is a value and if the
value isnt already in the other cells i.e:

A B C D E Concatenated (should Read):
Row 1: United Kingdom France Japan United Kingdom Italy United Kingdom,
France , Japan, Italy
Row 2: USA USA USA USA
Row 3: France Singapore Italy Spain France France, Singapore, Italy, Spain,
Row 4: United Kingdom France United Kingdom United Kingdom United
Kingdom United Kingdom, France


the following formula works to a point...
=SUBSTITUTE(TRIM(CONCATENATE(A1," ",B1," ",C1," ",D1," ",E1))," ",", ")

it brings back the following for Row 4 (mentioned above)

Row 4: United, Kingdom, France, United, Kingdom, United, Kingdom, United,
Kingdom

Where I would like it to read: United Kingdom, France

Is this possible?

Many thanks
Tracey

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 857
Default Concatenate With Criteria

Hi,

Please see my response to your previous post.

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Tracey" wrote:

hello

I have 5 columns that I need to concatenate IF there is a value and if the
value isnt already in the other cells i.e:

A B C D E Concatenated (should Read):
Row 1: United Kingdom France Japan United Kingdom Italy United Kingdom,
France , Japan, Italy
Row 2: USA USA USA USA
Row 3: France Singapore Italy Spain France France, Singapore, Italy, Spain,
Row 4: United Kingdom France United Kingdom United Kingdom United
Kingdom United Kingdom, France


the following formula works to a point...
=SUBSTITUTE(TRIM(CONCATENATE(A1," ",B1," ",C1," ",D1," ",E1))," ",", ")

it brings back the following for Row 4 (mentioned above)

Row 4: United, Kingdom, France, United, Kingdom, United, Kingdom, United,
Kingdom

Where I would like it to read: United Kingdom, France

Is this possible?

Many thanks
Tracey

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 78
Default Concatenate With Criteria

Hi Shane,

Thanks for that... I've done that (I think I'm being a little daft) but I
get #NAME? when I run that...
do I need to change anything in the VBA part? (obviously I've changed the
data range from
A1:E1 to the correct range)

Thanks again for your help
Trace
******************************************

"Shane Devenshire" wrote:

Hi,

Please see my response to your previous post.

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Tracey" wrote:

hello

I have 5 columns that I need to concatenate IF there is a value and if the
value isnt already in the other cells i.e:

A B C D E Concatenated (should Read):
Row 1: United Kingdom France Japan United Kingdom Italy United Kingdom,
France , Japan, Italy
Row 2: USA USA USA USA
Row 3: France Singapore Italy Spain France France, Singapore, Italy, Spain,
Row 4: United Kingdom France United Kingdom United Kingdom United
Kingdom United Kingdom, France


the following formula works to a point...
=SUBSTITUTE(TRIM(CONCATENATE(A1," ",B1," ",C1," ",D1," ",E1))," ",", ")

it brings back the following for Row 4 (mentioned above)

Row 4: United, Kingdom, France, United, Kingdom, United, Kingdom, United,
Kingdom

Where I would like it to read: United Kingdom, France

Is this possible?

Many thanks
Tracey

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Concatenate With Criteria

Oops, I fear I led you astray. You need to post the code into a module
(Insert-Module), not into the regular sheet coding.

My apologies.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Tracey" wrote:

Hi Shane,

Thanks for that... I've done that (I think I'm being a little daft) but I
get #NAME? when I run that...
do I need to change anything in the VBA part? (obviously I've changed the
data range from
A1:E1 to the correct range)

Thanks again for your help
Trace
******************************************

"Shane Devenshire" wrote:

Hi,

Please see my response to your previous post.

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Tracey" wrote:

hello

I have 5 columns that I need to concatenate IF there is a value and if the
value isnt already in the other cells i.e:

A B C D E Concatenated (should Read):
Row 1: United Kingdom France Japan United Kingdom Italy United Kingdom,
France , Japan, Italy
Row 2: USA USA USA USA
Row 3: France Singapore Italy Spain France France, Singapore, Italy, Spain,
Row 4: United Kingdom France United Kingdom United Kingdom United
Kingdom United Kingdom, France


the following formula works to a point...
=SUBSTITUTE(TRIM(CONCATENATE(A1," ",B1," ",C1," ",D1," ",E1))," ",", ")

it brings back the following for Row 4 (mentioned above)

Row 4: United, Kingdom, France, United, Kingdom, United, Kingdom, United,
Kingdom

Where I would like it to read: United Kingdom, France

Is this possible?

Many thanks
Tracey



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 78
Default Concatenate With Criteria

You guys are Fabulous!!!!!

Thank you!!



"Luke M" wrote:

Oops, I fear I led you astray. You need to post the code into a module
(Insert-Module), not into the regular sheet coding.

My apologies.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Tracey" wrote:

Hi Shane,

Thanks for that... I've done that (I think I'm being a little daft) but I
get #NAME? when I run that...
do I need to change anything in the VBA part? (obviously I've changed the
data range from
A1:E1 to the correct range)

Thanks again for your help
Trace
******************************************

"Shane Devenshire" wrote:

Hi,

Please see my response to your previous post.

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Tracey" wrote:

hello

I have 5 columns that I need to concatenate IF there is a value and if the
value isnt already in the other cells i.e:

A B C D E Concatenated (should Read):
Row 1: United Kingdom France Japan United Kingdom Italy United Kingdom,
France , Japan, Italy
Row 2: USA USA USA USA
Row 3: France Singapore Italy Spain France France, Singapore, Italy, Spain,
Row 4: United Kingdom France United Kingdom United Kingdom United
Kingdom United Kingdom, France


the following formula works to a point...
=SUBSTITUTE(TRIM(CONCATENATE(A1," ",B1," ",C1," ",D1," ",E1))," ",", ")

it brings back the following for Row 4 (mentioned above)

Row 4: United, Kingdom, France, United, Kingdom, United, Kingdom, United,
Kingdom

Where I would like it to read: United Kingdom, France

Is this possible?

Many thanks
Tracey

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
Count how many criteria in a column match criteria in another colu Charles Stover Excel Discussion (Misc queries) 3 March 6th 09 08:39 PM
=DMIN(database,field,criteria) question about criteria Dummy Excel Discussion (Misc queries) 2 April 16th 07 08:02 PM
I know how to concatenate ,can one de-concatenate to split date? QUICK BOOKS PROBLEM- New Users to Excel 1 July 26th 05 05:07 PM
Counting Cells with multiple criteria.One criteria supporting wild Azhar Saleem Excel Worksheet Functions 1 January 12th 05 10:54 AM
Counting Cells with multiple criteria.One criteria supporting wild Azhar Arain Excel Worksheet Functions 1 January 12th 05 08:33 AM


All times are GMT +1. The time now is 05:15 PM.

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

About Us

"It's about Microsoft Excel"