Skip to content

Instantly share code, notes, and snippets.

@jesantos
Created October 11, 2011 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesantos/1277225 to your computer and use it in GitHub Desktop.
Save jesantos/1277225 to your computer and use it in GitHub Desktop.
Excel VBA; Merge Values using a delimiter
Function MERGEVALUES(rn As Range, del As String)
Dim cell As Range
Dim result As String
Dim index As Integer
Dim textSplit As Variant
Dim curVal As String
For Each cell In rn
textSplit = Split(cell.text, del)
For index = LBound(textSplit) To UBound(textSplit)
curVal = textSplit(index)
If result = "" Then
result = curVal
Else
If InStr(result, curVal & del) < 1 Then
result = result & del & curVal
End If
End If
Next
Next
MERGEVALUES = result
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment