Concatenate range

B

Bhuktar S

There are names speaded in a range A1 to K10. Some are blanks.
I want to add all these names with , between each name.
The names to be A1 to A10 + B1 to B10 + ....leaving blanks.
How do I do that?
 
G

Gord Dibben

Bhuktar

Select a range and run the macro. Your choice of de-limiter.
Blank cells will be omitted.

Note: can be run on contiguous or non-contiguous range.

Sub ConCat_Cells()
'comma delimited
Dim x As Range
Dim y As Range
Dim z As Range
Dim w As String
Dim sbuf As String
On Error GoTo endit
w = InputBox("Enter the Type of De-limiter")
Set z = Application.InputBox("Select Destination Cell", _
"Destination Cell", , , , , , 8)
Application.SendKeys "+{F8}"
Set x = Application.InputBox("Select Cells..Contiguous or Non-Contiguous", _
"Cells Selection", , , , , , 8)
For Each y In x
If Len(y.text) > 0 Then sbuf = sbuf & y.text & w
Next
z = Left(sbuf, Len(sbuf) - 1)
'Application.SendKeys "+{F8}"
Exit Sub
endit:
MsgBox "Nothing Selected. Please try again."
End Sub

Gord Dibben Excel MVP
 
Top