Wednesday, August 10, 2011

Concatenation of All String in Selection

if you want to Concatenate Some Data you can use this Code :




Sub ConcateAll()
    Dim Resultcell As Range
    Dim rng As Range
    Dim cell As Range
    Dim resultString As String
    Set rng = Application.InputBox("Please select A Range For Input ", , , , , , , 8)
    Set Resultcell = Application.InputBox("Please select A Range For Out ", , , , , , , 8)
    resultString = ""
    For Each cell In rng
        resultString = resultString & " " & cell.Value
    Next
    Resultcell = resultString
End Sub

1 comment:

Brian said...

Here is a UDF

Function joyn(what As Range, Optional Sep As String) As String
Dim Item As Range
Application.Volatile
For Each Item In what: joyn = joyn & IIf(Len(Item) > 0, Item & Sep, "")
Next Item: joyn = Left(joyn, Len(joyn) - IIf(Len(Sep) > 0, Len(Sep), 0))
End Function