Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Joining the contents of several cells into a single one

I know that to join the contents of several cells into a single one
(concatenate is the technical word), all it takes is the function & and that
to have values separated by a comma and a space all you have to do is:
a1&", "&a2&", "&a3&", "&a4

My problem is that sometimes some of these cells are empty so I end up with
some values separated by commas, empty spaces and more commas without more
values in between.

What would be the way to concatenate only the non-empty cells?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15,768
Default Joining the contents of several cells into a single one

Do any of cells you want to concatenate *already* contain commas and/or
spaces?

--
Biff
Microsoft Excel MVP


"Jorge E. Jaramillo" wrote in
message ...
I know that to join the contents of several cells into a single one
(concatenate is the technical word), all it takes is the function & and
that
to have values separated by a comma and a space all you have to do is:
a1&", "&a2&", "&a3&", "&a4

My problem is that sometimes some of these cells are empty so I end up
with
some values separated by commas, empty spaces and more commas without more
values in between.

What would be the way to concatenate only the non-empty cells?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,651
Default Joining the contents of several cells into a single one

It's messy, but you could change your
=a1&", "&a2&", "&a3&", "&a4
along the lines of
=IF(A1="","",a1&", ")&IF(A2="","",a2&", ")&IF(A3="","",a3&", ")&a4
--
David Biddulph

"Jorge E. Jaramillo" wrote in
message ...
I know that to join the contents of several cells into a single one
(concatenate is the technical word), all it takes is the function & and
that
to have values separated by a comma and a space all you have to do is:
a1&", "&a2&", "&a3&", "&a4

My problem is that sometimes some of these cells are empty so I end up
with
some values separated by commas, empty spaces and more commas without more
values in between.

What would be the way to concatenate only the non-empty cells?

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15,768
Default Joining the contents of several cells into a single one

If the last cells are empty that leaves a comma at the end of the string.

x, y,

Try this: (all on one line):

=SUBSTITUTE(TRIM(A1&" "&A2&" "
&A3&" "&A4)," ",", ")

x, y

However, if the cells already contain spaces and/or commas the result won't
look right.

--
Biff
Microsoft Excel MVP


"David Biddulph" <groups [at] biddulph.org.uk wrote in message
...
It's messy, but you could change your
=a1&", "&a2&", "&a3&", "&a4
along the lines of
=IF(A1="","",a1&", ")&IF(A2="","",a2&", ")&IF(A3="","",a3&", ")&a4
--
David Biddulph

"Jorge E. Jaramillo" wrote in
message ...
I know that to join the contents of several cells into a single one
(concatenate is the technical word), all it takes is the function & and
that
to have values separated by a comma and a space all you have to do is:
a1&", "&a2&", "&a3&", "&a4

My problem is that sometimes some of these cells are empty so I end up
with
some values separated by commas, empty spaces and more commas without
more
values in between.

What would be the way to concatenate only the non-empty cells?

Thanks





  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,180
Default Joining the contents of several cells into a single one

Or without formulas:
Copy/PasteSpecial the cells you want to concatenate into Word as
"Unformatted Text"
Find/Replace. Check "use wildcards".
Find what: ^t{1,}
Replace with: ,
Or export the concatenated string (with multiple commas) into Word.
Find what: ,{1,}
Replace with: ,
Copy/Paste back into Excel



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default Joining the contents of several cells into a single one

On Sat, 1 Nov 2008 21:26:00 -0700, Jorge E. Jaramillo
wrote:

I know that to join the contents of several cells into a single one
(concatenate is the technical word), all it takes is the function & and that
to have values separated by a comma and a space all you have to do is:
a1&", "&a2&", "&a3&", "&a4

My problem is that sometimes some of these cells are empty so I end up with
some values separated by commas, empty spaces and more commas without more
values in between.

What would be the way to concatenate only the non-empty cells?

Thanks


Here's one method.

Download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr

Then use this formula to concatenate, for example, A1:A5 :

=IF(ISERR(FIND(", ",SETV(MCONCAT(A1:A5,", ")),
LEN(GETV())-1)),GETV(),LEFT(GETV(),LEN(GETV())-2))


The total length of the string must be less than 256 characters. If it is
longer, a VBA routine could be used.
--ron
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15,768
Default Joining the contents of several cells into a single one

Here's another method using the Morefunc add-in.

Array entered** :

=SUBSTITUTE(TRIM(MCONCAT(IF(
A1:A5<"",A1:A5,"")&" "))," ",", ")

The same caveat applies, the resulting string must be less than 256
characters.

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER)

--
Biff
Microsoft Excel MVP


"Ron Rosenfeld" wrote in message
...
On Sat, 1 Nov 2008 21:26:00 -0700, Jorge E. Jaramillo
wrote:

I know that to join the contents of several cells into a single one
(concatenate is the technical word), all it takes is the function & and
that
to have values separated by a comma and a space all you have to do is:
a1&", "&a2&", "&a3&", "&a4

My problem is that sometimes some of these cells are empty so I end up
with
some values separated by commas, empty spaces and more commas without more
values in between.

What would be the way to concatenate only the non-empty cells?

Thanks


Here's one method.

Download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr

Then use this formula to concatenate, for example, A1:A5 :

=IF(ISERR(FIND(", ",SETV(MCONCAT(A1:A5,", ")),
LEN(GETV())-1)),GETV(),LEFT(GETV(),LEN(GETV())-2))


The total length of the string must be less than 256 characters. If it is
longer, a VBA routine could be used.
--ron



  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Joining the contents of several cells into a single one

Thank you for the answers. I am going to try them. Just so you know, cells
content is only either empty or short text string without spaces or commas.
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
Joining numbered cells prefixed with zero Petee Excel Worksheet Functions 1 April 10th 08 04:52 PM
compare the contents of one range of cells with the contents of a. Dozy123 Excel Discussion (Misc queries) 1 January 24th 07 10:14 AM
Very Basic Problem - Merged Cell Equals Contents of a Single Cell jollynicechap Excel Worksheet Functions 3 December 29th 06 08:16 PM
Copy column range of "single word" cells with spaces to a single c nastech Excel Discussion (Misc queries) 3 February 15th 06 05:04 PM
Joining letters from different cells Lance Excel Worksheet Functions 3 October 9th 05 06:05 PM


All times are GMT +1. The time now is 11:16 AM.

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"