Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Text_Joined(Delimiter As Variant, IgnoreEmptyCells As Boolean, TextRange As Range) As Variant
  2. Dim textarray()
  3. If IgnoreEmptyCells = True Then
  4.     For i = 1 To TextRange.Cells.Count
  5.         If TextRange.Cells(i) <> "" Then
  6.             k = k + 1
  7.             ReDim Preserve textarray(1 To k)
  8.             textarray(k) = TextRange.Cells(i)
  9.         End If
  10.     Next i
  11. Else
  12.     For i = 1 To TextRange.Cells.Count
  13.         k = k + 1
  14.         ReDim Preserve textarray(1 To k)
  15.         textarray(k) = TextRange.Cells(i)
  16.     Next i
  17. End If
  18.  
  19. 'Now Join the Cells
  20. If Not TypeName(Delimiter) = "Range" Then
  21.  
  22.     Text_Joined = textarray(1)
  23.         For i = 2 To UBound(textarray) - 1
  24.         Text_Joined = Text_Joined & Delimiter & textarray(i)
  25.         Next i
  26.    
  27.     If i > 1 Then Text_Joined = Text_Joined & Delimiter & textarray(UBound(textarray))
  28. Else
  29.  
  30.    Text_Joined = textarray(1)
  31.        
  32.         For i = 2 To UBound(textarray) - 1
  33.             l = l + 1
  34.             If l = Delimiter.Cells.Count + 1 Then l = 1
  35.         Text_Joined = Text_Joined & Delimiter.Cells(l) & textarray(i)
  36.         Next i
  37.    
  38.     If i > 1 Then Text_Joined = Text_Joined & Delimiter.Cells(l + i) & textarray(UBound(textarray))
  39.  
  40. End If
  41.  
  42. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement