congdantoancau

[VBA] CONCATENATEMULTIPLE

Sep 14th, 2020 (edited)
1,921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function CONCATENATEMULTIPLE(Ref As Range, Optional Separator As String) As String
  2.     Dim Cell As Range
  3.     Dim Result As String
  4.    
  5.     If IsNull(Separator) Then
  6.         Separator = ""
  7.     End If
  8.        
  9.     For Each Cell In Ref
  10.         Result = Result & Cell.Value & Separator
  11.     Next Cell
  12.     If Separator = "" Then
  13.         CONCATENATEMULTIPLE = Result
  14.     Else
  15.         CONCATENATEMULTIPLE = Left(Result, Len(Result) - 1)
  16.     End If
  17. End Function
  18.  
Advertisement
Add Comment
Please, Sign In to add comment