I want to create user defined function not already defined function. Also I am looking out for the code for the same.Hi !
Start to see Join function in VBA help …
Public Function JoinText(inputrange As Range, Optional sep As String) As Variant
Dim cell As Range
For Each cell In inputrange
If cell.Text <> vbNullString Then
outstring = outstring & IIf(sep <> vbNullString, sep, ",") & cell.Text
End If
Next
JoinText = Mid(outstring, IIf(Len(sep) = 0, 1, Len(sep)) + 1)
End Function
Function JoinRange$(Rg As Range, DELIM$)
JoinRange = Join(Evaluate("TRANSPOSE(TRANSPOSE(" & Rg.Address(, , , True) & "))"), DELIM)
End Function
Different method.Hi,
I want vba code for UDF jointext where syntax of the function will =jointtext("A1:E1",",") which will give me o/p as below :
Suppose a b c d e are written in column A1 to E1 respectively then jointext function should return me answer as a,b,c,d,e.
Function jointext(rng As Range, joinStr As String) As String
jointext = Join(Filter(rng.Parent.Evaluate("if(" & rng.Address & _
"<>""""," & rng.Address & ",cha(2))"), Chr(2), 0), joinStr)
End Function
Yes, I am. How do you know?Hi jindon ! (from Japan ?)
Little typo in your code : Cha instead of Chr ?
Yes, I am. How do you know?
Public Function JoinText(rng As Range, strDelim As String) As String
JoinText = Replace(Application.Trim(Join(Application.Transpose(Application.Transpose(rng.Value)), " ")), " ", strDelim)
End Function