• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

UDF to concatenate non blank cells in a range

If you want to concatenate non blank cells in a range.

Code:
Function concatenate_nonblanks(irng As Range, spl As String)
Dim cell As Range
Dim rsl As String
 
For Each cell In irng
If cell <> vbNullString Then
rsl = rsl & spl & cell
End If
Next
 
concatenate_nonblanks = Right(rsl, Len(rsl) - Len(spl))
End Function

For example - you want to concatenate all non blank cells in range a1:a20 with (,) as separator . Try

=concatenate_nonblanks(A1:a20,",")

A1:a20 - is range which you want to concatenate to single cell


"," - pass separator in double quotes
 
This should work like above:

Code:
Function Concat_Range(rngJoin As Range, strSep As String) As String
Concat_Range = Join(Filter(Application.Transpose(Evaluate("=IF(" & rngJoin.Address & "<>""""" _
& "," & rngJoin.Address & "," & """~""" & ")")), "~", False), strSep)
End Function
 
Back
Top