Concatenate cells and adding + sign, but skip if cell is blank.

scottwland

New Member
Joined
Jun 28, 2011
Messages
3
I need to concatenate cells with a plus sign added in-between each of the cells content. However if some of the cells are blank I don't want the extra + signs added from each blank cell. I assume I need and If Then statement


My formula looks like this
=B1&"+"&C1&"+"&D1&"+"&E1&"+"&F1

My output looks like this with all fields containing a value.
<style>table { }td { padding-top: 1px; padding-right: 1px; padding-left: 1px; color: windowtext; font-size: 10pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Verdana; vertical-align: bottom; border: medium none; white-space: nowrap; }</style> <table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="153"> <col style="" width="153"> <tbody><tr height="13"> <td height="13" width="153">b1+c1+d1+e1+f1</td> </tr> </tbody></table>
But this is what it looks like when I have blank fields
<style>table { }td { padding-top: 1px; padding-right: 1px; padding-left: 1px; color: windowtext; font-size: 10pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Verdana; vertical-align: bottom; border: medium none; white-space: nowrap; }</style> <table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="153"> <col style="" width="153"> <tbody><tr height="13"> <td height="13" width="153">b2+c2+++f2</td> </tr> </tbody></table>
I need to eliminate the 2 extra + signs in the output.

Thanks for any help. This is a little over my formula building head.

Scott
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Maybe a UDF

Code:
Function concat(r As Range) As String
Dim c As Range
For Each c In r
    If c.Value <> "" Then concat = concat & c.Value & "+"
Next c
If concat <> "" Then concat = Left(concat, Len(concat) - 1)
End Function
 
Upvote 0
Hi Mike

I just found an issue with the formula you helped me with in June. One of the fields that is being concatenated is a zip code field and if the zip code starts with a zero, the zero is left out when the formula is generated. I have tried to change the formatting of the field to text field and the zero still disappears. Do you know what i need to do to keep the digit?

Thank you

Scott
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top