ashish koul
Member
If you want to concatenate non blank cells in a range.
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
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