Hi All,
I am using the concat code of Chandoo to concatenate a range of cells.
It's very useful for me.
The result of the code is like this.
Eg:-
A1= APPLE
A2= ORANGE
A3= BANANA
while executing the concat code the result will be like this. [=CONCAT(A1:A3),,)]
APPLE,ORANGE,BANANA
But the result shoud be like this in one cell like this.(In a single cell, like using Alt + Enter)
APPLE
ORANGE
BANANA
The code which is i am using:
Function concat(useThis As Range, Optional delim As String) As String
' this function will concatenate a range of cells and return one string
' useful when you have a rather large range of cells that you need to add up
Dim retVal, dlm As String
retVal = ""
If delim = Null Then
dlm = ""
Else
dlm = delim
End If
For Each cell In useThis
if cstr(cell.value)<>"" and cstr(cell.value)<>" " then
retVal = retVal & cstr(cell.Value) & dlm
end if
Next
If dlm <> "" Then
retVal = Left(retVal, Len(retVal) - Len(dlm))
End If
concat = retVal
End Function
Kindly do the needful.
Thanks,
Vargeesh
I am using the concat code of Chandoo to concatenate a range of cells.
It's very useful for me.
The result of the code is like this.
Eg:-
A1= APPLE
A2= ORANGE
A3= BANANA
while executing the concat code the result will be like this. [=CONCAT(A1:A3),,)]
APPLE,ORANGE,BANANA
But the result shoud be like this in one cell like this.(In a single cell, like using Alt + Enter)
APPLE
ORANGE
BANANA
The code which is i am using:
Function concat(useThis As Range, Optional delim As String) As String
' this function will concatenate a range of cells and return one string
' useful when you have a rather large range of cells that you need to add up
Dim retVal, dlm As String
retVal = ""
If delim = Null Then
dlm = ""
Else
dlm = delim
End If
For Each cell In useThis
if cstr(cell.value)<>"" and cstr(cell.value)<>" " then
retVal = retVal & cstr(cell.Value) & dlm
end if
Next
If dlm <> "" Then
retVal = Left(retVal, Len(retVal) - Len(dlm))
End If
concat = retVal
End Function
Kindly do the needful.
Thanks,
Vargeesh