1 Attachment(s)
Help : Join String with Delimiter - need to have the option of downward or rightward
Hi,
Thanks for the continued support from all the expert members in VBA Express
This time I would like have an option to choose the route to join strings.
Currently the code is joining values from the right first, I need to have option to choose whether the joinstring shall go downwards or rightwards.
http://www.vbaexpress.com/forum/imag...AAAElFTkSuQmCC
Code:
Option Explicit
Sub JoinString()
Dim xJoinRange As Range, xDestination As Range, Rng As Range
Dim Delimiter As String, OutputValue As String
On Error Resume Next
'Set xJoinRange = Application.InputBox(prompt:="Select source cells to merge", Type:=8)
Set xJoinRange = Selection
'On Error GoTo 0
'If xJoinRange Is Nothing Then Exit Sub
Set xDestination = Application.InputBox(prompt:="Select destination cell", Type:=8)
Delimiter = Application.InputBox(prompt:="Delimiter", Type:=2)
For Each Rng In xJoinRange
If Len(Trim(Rng.Value)) = 0 Then GoTo NextCell
OutputValue = OutputValue & Rng.Value & Delimiter
NextCell:
Next
xDestination.Value = Left(OutputValue, Len(OutputValue) - Len(Delimiter))
On Error GoTo 0
End Sub