Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PeterW
 
Posts: n/a
Default Concatenate and remove blanks


Hi

I am trying to concatenate a number of labels together separated by a
comma. However, if one of these cells is blank I end up with a number
of blanks together. For example A , B , C ,,,,,,,,G,H etc

As I want to remove these excess commas from the label I tried to use
the "Substitute" formula, as follows

=SUBSTITUTE(+F43&" , "&F44&" , "&F45&" , "&F46&" , "&F47&" , "&F48&" ,
"&F49&" , "&F50&" , "&F51&" , "&F52&" , "&F53&" , "&F54&" , "&F55&" ,
"&F56,",,","") ...... but it only removes every second comma

The real formula actually concatenates a lot mor cells than mentioned
in the above formula, so I can't use any "If" or "ISBlank" functions as
I will exceed the character limit of 256.

Does anyone have any other approach please?

Thanks in advance

Peter


--
PeterW
------------------------------------------------------------------------
PeterW's Profile: http://www.excelforum.com/member.php...fo&userid=6496
View this thread: http://www.excelforum.com/showthread...hreadid=502775

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JE McGimpsey
 
Posts: n/a
Default Concatenate and remove blanks

One way, using a User Defined Function:

Public Function CatNonBlanks( _
ByRef rRng As Excel.Range, _
Optional ByVal sDelim As String = "") As String
Dim rCell As Range
Dim sTemp As String
For Each rCell In rRng
If Not IsEmpty(rCell.Value) Then _
sTemp = sTemp & sDelim & rCell.Text
Next rCell
CatNonBlanks = Mid(sTemp, Len(sDelim) + 1, 32767)
End Function


If you're not familiar with UDFs, see

http://www.mvps.org/dmcritchie/excel/getstarted.htm


In article ,
PeterW wrote:

Hi

I am trying to concatenate a number of labels together separated by a
comma. However, if one of these cells is blank I end up with a number
of blanks together. For example A , B , C ,,,,,,,,G,H etc

As I want to remove these excess commas from the label I tried to use
the "Substitute" formula, as follows

=SUBSTITUTE(+F43&" , "&F44&" , "&F45&" , "&F46&" , "&F47&" , "&F48&" ,
"&F49&" , "&F50&" , "&F51&" , "&F52&" , "&F53&" , "&F54&" , "&F55&" ,
"&F56,",,","") ...... but it only removes every second comma

The real formula actually concatenates a lot mor cells than mentioned
in the above formula, so I can't use any "If" or "ISBlank" functions as
I will exceed the character limit of 256.

Does anyone have any other approach please?

Thanks in advance

Peter

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PeterW
 
Posts: n/a
Default Concatenate and remove blanks


Beautiful ... that works


--
PeterW
------------------------------------------------------------------------
PeterW's Profile: http://www.excelforum.com/member.php...fo&userid=6496
View this thread: http://www.excelforum.com/showthread...hreadid=502775

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max
 
Posts: n/a
Default Concatenate and remove blanks

An alternative to try, which could neatly remove excess commas
for any blank cells within the concat range would be something like:

=SUBSTITUTE(TRIM(F43&" "&F44&" "&F45&" "&F46&" "&F47&" "&F48&" "
&F49&" "&F50&" "&F51&" "&F52&" "&F53&" "&F54&" "&F55&" "&F56)," "," , ")
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"PeterW" wrote in
message ...

Hi

I am trying to concatenate a number of labels together separated by a
comma. However, if one of these cells is blank I end up with a number
of blanks together. For example A , B , C ,,,,,,,,G,H etc

As I want to remove these excess commas from the label I tried to use
the "Substitute" formula, as follows

=SUBSTITUTE(+F43&" , "&F44&" , "&F45&" , "&F46&" , "&F47&" , "&F48&" ,
"&F49&" , "&F50&" , "&F51&" , "&F52&" , "&F53&" , "&F54&" , "&F55&" ,
"&F56,",,","") ...... but it only removes every second comma

The real formula actually concatenates a lot mor cells than mentioned
in the above formula, so I can't use any "If" or "ISBlank" functions as
I will exceed the character limit of 256.

Does anyone have any other approach please?

Thanks in advance

Peter


--
PeterW
------------------------------------------------------------------------
PeterW's Profile:

http://www.excelforum.com/member.php...fo&userid=6496
View this thread: http://www.excelforum.com/showthread...hreadid=502775



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
Remove spaces between words Heather Tavitian Excel Discussion (Misc queries) 2 October 1st 05 01:47 AM
How do I remove hyphens from a product UPC? skpdpnt Excel Worksheet Functions 2 August 12th 05 05:50 PM


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