Concatenate with line break but only if text exists

jamiek

New Member
Joined
Dec 14, 2013
Messages
15
Office Version
  1. 365
Hi,

I am trying to combine shipping address information but some cells are blank e.g. some addresses have a company name, some don't which leaves an empty line.

I am using the below formula.

Excel Formula:
=A2 &CHAR(10)& B2 &CHAR(10)& C2 &CHAR(10)& D2 &CHAR(10)& E2 &CHAR(10)& F2

How can I make it so if a cell is empty that it doesn't include it resulting in an empty line?

Screenshot 2021-11-11 at 12.54.55.png


Cheers,
J
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

If you have xl2019 or newer you could use textjoin
 
Upvote 0
If you do have TEXTJION then. like.
Excel Formula:
=TEXTJOIN(CHAR(10),TRUE,A2,B2,C2,D2,E2)

Otherwise in older Excel versions you could try

Excel Formula:
=SUBSTITUTE(SUBSTITUTE(A2&"^"&B2&"^"&C2&"^"&D2&"^"&E2,"^^",""),"^",CHAR(10))

Hope that helps.
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

If you have xl2019 or newer you could use textjoin
Ok thanks updated my profile it is 16.34.
 
Upvote 0
Thanks for that, you can either use the textjoin formula provided by Snakehips, or this one
Excel Formula:
=TEXTJOIN(CHAR(10),,A2:E2)
 
Upvote 0
If you do have TEXTJION then. like.
Excel Formula:
=TEXTJOIN(CHAR(10),TRUE,A2,B2,C2,D2,E2)

Otherwise in older Excel versions you could try

Excel Formula:
=SUBSTITUTE(SUBSTITUTE(A2&"^"&B2&"^"&C2&"^"&D2&"^"&E2,"^^",""),"^",CHAR(10))

Hope that helps.
Thanks Snakehips! The TEXTJOIN formula is working a treat :)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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