View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld[_2_] Ron Rosenfeld[_2_] is offline
external usenet poster
 
Posts: 1,045
Default concatenate a range of data

On Sat, 17 Mar 2012 06:04:15 -0700 (PDT), jt wrote:

is there a way to concatenate a range instead of having to
individually select each cell, thanks in advance


Here is a User Defined Function you can use:

To enter this User Defined Function (UDF), <alt-F11 opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this User Defined Function (UDF), enter a formula like

=ConcatRange(range, [delimiter])

in some cell.

The delimiter is optional and, if omitted, will default to a <space


==========================
Option Explicit
Function ConcatRange(rg As Range, Optional sDelim As String = " ") As String
Dim v1 As Variant, v2() As Variant, v As Variant
Dim i As Long
v1 = rg
ReDim v2(0 To rg.Count - 1)
i = 0
For Each v In v1
v2(i) = v
i = i + 1
Next v
ConcatRange = Join(v2, sDelim)
End Function
===============================