Only concatenate cells with value

justrying

New Member
Joined
Jul 14, 2021
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
I have a problem when I try to chain together cells with separating them with commas.

For example, if I want to concatenate A2:D2 with separated commas, I use =CONCATENATE(TRANSPOSE(A2:D2)&", "). Like shown here:

A​
B​
C​
D​
E​
1​
Picture 1Picture 2Picture 3Picture 4Pictures
2​
1.jpg​
2.jpg​
3.jpg​
4.jpg​
1.jpg, 2.jpg, 3.jpg, 4.jpg,

But if, for example, C2 and D2 are empty, I don't want commas to appear. In other words, only the cells that have a value must be chained together with comma seperator.
It would also be ideal not to get a comma after the last number as shown in E2 in the example above, if possible.
Problem shown here:
A​
B​
C​
D​
E​
1​
Picture 1Picture 2Picture 3Picture 4Pictures
2​
1.jpg​
2.jpg​
1.jpg, 2.jpg, , ,


How can I solve this?

Thanks in advance.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try TEXTJOIN:

Book1
ABCDE
1Picture 1Picture 2Picture 3Picture 4Pictures
21.jpg2.jpg4.jpg1.jpg, 2.jpg, 4.jpg
Sheet1
Cell Formulas
RangeFormula
E2E2=TEXTJOIN(", ",1,A2:D2)
 
Upvote 0
Solution
One more thing. Would it be possible for it to only combine cells that have more than, say, 5 characters?
 
Upvote 0
You can do something like this:

Book1
ABCDE
1Picture 1Picture 2Picture 3Picture 4Pictures
2RocketCarBicycleRocket, Bicycle
Sheet1
Cell Formulas
RangeFormula
E2E2=TEXTJOIN(", ",1,IF(LEN(A2:D2)>5,A2:D2,""))
Press CTRL+SHIFT+ENTER to enter array formulas.


With Excel 2019, you need to use Control+Shift+Enter.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,537
Members
449,088
Latest member
RandomExceller01

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