Last active
December 17, 2015 08:39
-
-
Save stevehenderson/5581796 to your computer and use it in GitHub Desktop.
VBA function to concatenate an entire range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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