Skip to content

Instantly share code, notes, and snippets.

@stevehenderson
Last active December 17, 2015 08:39
Show Gist options
  • Save stevehenderson/5581796 to your computer and use it in GitHub Desktop.
Save stevehenderson/5581796 to your computer and use it in GitHub Desktop.
VBA function to concatenate an entire range
Function ConcatenateAll(rng As Range)
Dim x As String, y As String, cel As Range
With ActiveSheet
For Each cel In rng
y = cel.Value
If y <> "" Then
x = x & cel.Value & ", "
End If
Next
End With
Dim c As String
x = Trim(x)
c = Right(x, 1)
If c = "," Then
x = Left(x, Len(x) - 1)
End If
ConcatenateAll = x
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment