Concatenation of multiple strings is a very common practice for MS Excel users. I have noticed many people wanting to concatenate cells with a comma delimiter in between the values but they run into issues when there are blank cells in the data set.
Consider the data set below containing information about flight departures and their itineraries.
The goal is to concatenate columns “B” to “F”. Here is how the outcome will look like when a conventional “CONCATENATE” formula is used.
As you could observe, we get too many extra commas if any of the cells in the respective rows contain nulls.
The solution to this issue is to use the CONCATENATE formula in conjunction with the SUBSTITUTE and TRIM formulas and therefore omitting extra commas =SUBSTITUTE(TRIM(CONCATENATE(B2," ",C2," ",D2," ",E2," ",F2)), " ", ",") Note that there is a small variation in the inner part of the formula and that is that when we CONCATENATE the values we no longer use comma as the delimiter but rather we are using space as the delimiter. By doing so, every time there is a space between two values the space will be replaced with a comma and therefore extra commas won’t be included in the result. Here is the final desired outcome with no extra commas.
1 Comment
|
CategoriesArchives
June 2020
|