Concatenate

G

Guest

When using concatenate if I have cells that are empty in
that row how can I disregard including the empty cell,
without typing function in manually for each row ?

Example:
Col 1 Col 2 Col 3 Col 4 Col 5
Dan Dave Paul Sue

Function I use is
=CONCATENATE(A1,",",B1,",",C1,",",E1,",",)
Results I receive are: Dan,,Dave,Paul, Sue
Like to see: Dan, Dave, Paul, Sue
 
M

Max

Try in say, F1:

=SUBSTITUTE(TRIM(A1&" "&B1&" "&C1&" "&D1&" "&E1)," ",", ")

Copy F1 down

The above essentially uses TRIM to remove any extraneous "in-between" spaces
from the concat string first, then SUBSTITUTE will replace all the single
spaces: " " in between words with a comma-space: ", " to give the desired
result
 
B

Biff

Hi!

Upon further testing I discovered that my formula only
works under certain conditions.

Use Max's formula, it's more robust.

Biff
 
G

Gord Dibben

JT

In addition to Max's solution you could use a User Defined Function that
ignores blank 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(A1:E1) which will ignore D1


Gord Dibben Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top