1

how can I concatenate the Values in Cells B1:K1 to receive the string in A1. Empty cells should be omitted. Is this possible using Excel commands or only with vba?

enter image description here

5
  • Maybe there's a more elegant solution but you could just use CONCATENATE, or an ampersand: =B1&C1&D1&E1&F1&G1&H1&I1&J1&K1 Commented Nov 28, 2017 at 15:58
  • 1
    What Excel are you using? Commented Nov 28, 2017 at 15:58
  • 1
    If using >=Excel 2016 then you could try using TEXTJOIN link Commented Nov 28, 2017 at 16:11
  • @Absinthe: I used concatenate already. However, that does not remove duplicates so that you get a string like a,b,a,c, , b.... which is not what I am trying to achieve. Commented Nov 28, 2017 at 16:46
  • @Scott: using MS Office 2010 Prof. Commented Nov 28, 2017 at 16:47

3 Answers 3

3

If you have Office 365 Excel then you can use an Array form of TEXTJOIN:

=TEXTJOIN(", ",TRUE,INDEX(1:1,,N(IF({1},MODE.MULT(IF((IFERROR(MATCH(B1:K1,B1:K1,0)=COLUMN(B1:K1)-MIN(COLUMN(B1:K1))+1,0))*(B1:K1<>""),COLUMN(B1:K1)*{1;1}))))))

Being an array it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

enter image description here


If you do not have office 365 Excel you will need vba. This UDF will mimic the TEXTJOIN. Put it in a module attached to the workbook and use the formula as described above.

Function TEXTJOIN(delim As String, skipblank As Boolean, arr)
    Dim d As Long
    Dim c As Long
    Dim arr2()
    Dim t As Long, y As Long
    t = -1
    y = -1
    If TypeName(arr) = "Range" Then
        arr2 = arr.Value
    Else
        arr2 = arr
    End If
    On Error Resume Next
    t = UBound(arr2, 2)
    y = UBound(arr2, 1)
    On Error GoTo 0

    If t >= 0 And y >= 0 Then
        For c = LBound(arr2, 1) To UBound(arr2, 1)
            For d = LBound(arr2, 1) To UBound(arr2, 2)
                If arr2(c, d) <> "" Or Not skipblank Then
                    TEXTJOIN = TEXTJOIN & arr2(c, d) & delim
                End If
            Next d
        Next c
    Else
        For c = LBound(arr2) To UBound(arr2)
            If arr2(c) <> "" Or Not skipblank Then
                TEXTJOIN = TEXTJOIN & arr2(c) & delim
            End If
        Next c
    End If
    TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - Len(delim))
End Function
Sign up to request clarification or add additional context in comments.

Comments

0

I found a newer simpler version:

=IFERROR(TEXTJOIN(", ",TRUE,UNIQUE(B1:K1,TRUE,FALSE)),"")

And also one that works if the cells you want to combine are already lists:

=IFERROR(TEXTJOIN(", ", TRUE, UNIQUE(TEXTSPLIT(TEXTJOIN(", ",TRUE,B1:K1),", "),TRUE,FALSE)),"")

Comments

0

I would use a solution like this.

=IFERROR(TEXTJOIN(",",TRUE,FILTER(B1:K1,B1:K1<>"","")))

The filter will garantee you don´t use empty cells and will maintein the cells that are duplicated.
If you don´t want to show duplicated values you can use unique after the filter.

=IFERROR(TEXTJOIN(",",TRUE,UNIQUE(FILTER(B1:K1,B1:K1<>"",""))))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.