Skip to content

Instantly share code, notes, and snippets.

@longtth
Last active October 18, 2016 08:19
Show Gist options
  • Save longtth/0af3e917e2e0a26561cedd4dcd4e81c5 to your computer and use it in GitHub Desktop.
Save longtth/0af3e917e2e0a26561cedd4dcd4e81c5 to your computer and use it in GitHub Desktop.
Function concat(useThis As Range, Optional delim As String) As String
' this function will concatenate a range of cells and return one string
' useful when you have a rather large range of cells that you need to add up
Dim retVal, dlm As String
retVal = ""
If delim = Null Then
dlm = ""
Else
dlm = delim
End If
For Each cell In useThis
If CStr(cell.Value) <> "" And CStr(cell.Value) <> " " Then
retVal = retVal & CStr(cell.Value) & dlm
End If
Next
If dlm <> "" Then
retVal = Left(retVal, Len(retVal) - Len(dlm))
End If
concat = retVal
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment