Last active
October 18, 2016 08:19
-
-
Save longtth/0af3e917e2e0a26561cedd4dcd4e81c5 to your computer and use it in GitHub Desktop.
This file contains 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 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