Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 52
Default Concatenation and delimitter

In building a string based on THREE (or FOUR maybe in the future) columns
using CONCATENATE I am putting a "+" between each columns values. Problem is
that sometimes a value is blank, and therefore I don't want extra "+" in the
result. Please help me get "I Want" string results without a hideous nested
if statement. It is acceptable to add columns which store interim values to
help build string-- this is not a seen workbook. The "I Want" values
ultimately go into a Pivot table along with some other columns.

COL A COL B COL C My Result I Want
OK?
------- ------- ------- ---------------------
--------------------- -----
RED WHITE BLUE RED+WHITE+BLUE RED+WHITE+BLUE Y
RED WHITE RED+WHITE+ RED+WHITE N
+WHITE+ WHITE
N
RED RED++ RED
N
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Concatenation and delimitter

Data to be concat assumed in A2:C2 down
In D2: =SUBSTITUTE(TRIM(A2&" "&B2&" "&C2)," ","+")
Copy down
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:21,000 Files:365 Subscribers:65
xdemechanik
---
"KIM W" wrote:
In building a string based on THREE (or FOUR maybe in the future) columns
using CONCATENATE I am putting a "+" between each columns values. Problem is
that sometimes a value is blank, and therefore I don't want extra "+" in the
result. Please help me get "I Want" string results without a hideous nested
if statement. It is acceptable to add columns which store interim values to
help build string-- this is not a seen workbook. The "I Want" values
ultimately go into a Pivot table along with some other columns.

COL A COL B COL C My Result I Want
OK?
------- ------- ------- ---------------------
--------------------- -----
RED WHITE BLUE RED+WHITE+BLUE RED+WHITE+BLUE Y
RED WHITE RED+WHITE+ RED+WHITE N
+WHITE+ WHITE
N
RED RED++ RED
N

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 52
Default Concatenation and delimitter

Almost works as I need. Sorry I omitted a piece of information relevant to
your solution:
My real data has spaces in the string contents of each cell, e.g. "RED
STRIPE", "WHITE STRIPE", etc.
Your handy formula puts "+" between every single word, not just between
every concatenated value.

"Max" wrote:

Data to be concat assumed in A2:C2 down
In D2: =SUBSTITUTE(TRIM(A2&" "&B2&" "&C2)," ","+")
Copy down
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:21,000 Files:365 Subscribers:65
xdemechanik
---
"KIM W" wrote:
In building a string based on THREE (or FOUR maybe in the future) columns
using CONCATENATE I am putting a "+" between each columns values. Problem is
that sometimes a value is blank, and therefore I don't want extra "+" in the
result. Please help me get "I Want" string results without a hideous nested
if statement. It is acceptable to add columns which store interim values to
help build string-- this is not a seen workbook. The "I Want" values
ultimately go into a Pivot table along with some other columns.

COL A COL B COL C My Result I Want
OK?
------- ------- ------- ---------------------
--------------------- -----
RED WHITE BLUE RED+WHITE+BLUE RED+WHITE+BLUE Y
RED WHITE RED+WHITE+ RED+WHITE N
+WHITE+ WHITE
N
RED RED++ RED
N

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Concatenation and delimitter

This UDF will do what you need. Will ignore spaces in each cell and will
ignore empty cells.

Function ConCatRange(CellBlock As Range) As String
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.text) 0 Then sbuf = sbuf & Cell.text & "+"
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function

Usage is: =concatrange(A2:C2) entered in D2


Gord Dibben MS Excel MVP

On Fri, 12 Dec 2008 17:41:01 -0800, KIM W
wrote:

Almost works as I need. Sorry I omitted a piece of information relevant to
your solution:
My real data has spaces in the string contents of each cell, e.g. "RED
STRIPE", "WHITE STRIPE", etc.
Your handy formula puts "+" between every single word, not just between
every concatenated value.

"Max" wrote:

Data to be concat assumed in A2:C2 down
In D2: =SUBSTITUTE(TRIM(A2&" "&B2&" "&C2)," ","+")
Copy down
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:21,000 Files:365 Subscribers:65
xdemechanik
---
"KIM W" wrote:
In building a string based on THREE (or FOUR maybe in the future) columns
using CONCATENATE I am putting a "+" between each columns values. Problem is
that sometimes a value is blank, and therefore I don't want extra "+" in the
result. Please help me get "I Want" string results without a hideous nested
if statement. It is acceptable to add columns which store interim values to
help build string-- this is not a seen workbook. The "I Want" values
ultimately go into a Pivot table along with some other columns.

COL A COL B COL C My Result I Want
OK?
------- ------- ------- ---------------------
--------------------- -----
RED WHITE BLUE RED+WHITE+BLUE RED+WHITE+BLUE Y
RED WHITE RED+WHITE+ RED+WHITE N
+WHITE+ WHITE
N
RED RED++ RED
N


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,718
Default Concatenation and delimitter

Try this:

=SUBSTITUTE(TRIM(CONCATENATE(A1," ",B1," ",C1))," stripe "," stripe+")

case sensitive, you may replace "stripe" with "STRIPE"



"KIM W" wrote:

Almost works as I need. Sorry I omitted a piece of information relevant to
your solution:
My real data has spaces in the string contents of each cell, e.g. "RED
STRIPE", "WHITE STRIPE", etc.
Your handy formula puts "+" between every single word, not just between
every concatenated value.

"Max" wrote:

Data to be concat assumed in A2:C2 down
In D2: =SUBSTITUTE(TRIM(A2&" "&B2&" "&C2)," ","+")
Copy down
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:21,000 Files:365 Subscribers:65
xdemechanik
---
"KIM W" wrote:
In building a string based on THREE (or FOUR maybe in the future) columns
using CONCATENATE I am putting a "+" between each columns values. Problem is
that sometimes a value is blank, and therefore I don't want extra "+" in the
result. Please help me get "I Want" string results without a hideous nested
if statement. It is acceptable to add columns which store interim values to
help build string-- this is not a seen workbook. The "I Want" values
ultimately go into a Pivot table along with some other columns.

COL A COL B COL C My Result I Want
OK?
------- ------- ------- ---------------------
--------------------- -----
RED WHITE BLUE RED+WHITE+BLUE RED+WHITE+BLUE Y
RED WHITE RED+WHITE+ RED+WHITE N
+WHITE+ WHITE
N
RED RED++ RED
N



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 52
Default Concatenation and delimitter

Thanks! The UDF did it!

"Gord Dibben" wrote:

This UDF will do what you need. Will ignore spaces in each cell and will
ignore empty cells.

Function ConCatRange(CellBlock As Range) As String
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.text) 0 Then sbuf = sbuf & Cell.text & "+"
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function

Usage is: =concatrange(A2:C2) entered in D2


Gord Dibben MS Excel MVP

On Fri, 12 Dec 2008 17:41:01 -0800, KIM W
wrote:

Almost works as I need. Sorry I omitted a piece of information relevant to
your solution:
My real data has spaces in the string contents of each cell, e.g. "RED
STRIPE", "WHITE STRIPE", etc.
Your handy formula puts "+" between every single word, not just between
every concatenated value.

"Max" wrote:

Data to be concat assumed in A2:C2 down
In D2: =SUBSTITUTE(TRIM(A2&" "&B2&" "&C2)," ","+")
Copy down
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:21,000 Files:365 Subscribers:65
xdemechanik
---
"KIM W" wrote:
In building a string based on THREE (or FOUR maybe in the future) columns
using CONCATENATE I am putting a "+" between each columns values. Problem is
that sometimes a value is blank, and therefore I don't want extra "+" in the
result. Please help me get "I Want" string results without a hideous nested
if statement. It is acceptable to add columns which store interim values to
help build string-- this is not a seen workbook. The "I Want" values
ultimately go into a Pivot table along with some other columns.

COL A COL B COL C My Result I Want
OK?
------- ------- ------- ---------------------
--------------------- -----
RED WHITE BLUE RED+WHITE+BLUE RED+WHITE+BLUE Y
RED WHITE RED+WHITE+ RED+WHITE N
+WHITE+ WHITE
N
RED RED++ RED
N



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
Concatenation MichaelS Excel Discussion (Misc queries) 8 September 11th 08 07:54 AM
Concatenation ATHER Excel Worksheet Functions 2 May 19th 08 11:27 PM
Help with Concatenation alex Excel Worksheet Functions 3 August 28th 07 06:09 PM
Concatenation Harry Excel Worksheet Functions 2 July 17th 06 07:17 PM
Concatenation Ken Excel Discussion (Misc queries) 1 April 12th 06 11:26 AM


All times are GMT +1. The time now is 04:08 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"