• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

textjoin help

r121a947

Member
I am trying to create a textjoin macro that will recombine sorted words from a range of columns. The textjoin statement works in a single cell, but when I try to put it in a macro, I get a "syntax error" statement.

The macro code is:

Code:
Public Sub rejoinJ()

Dim i As Long
 
Dim lRow As Long

lRow = Cells(Rows.Count, 1).End(xlUp).Row

Dim curRow As Long

curRow = 1

For i = curRow To lRow


TEXTJOIN(" ", TRUE, "N" & curRow   & ":BA" & curRow)
' MsgBox curRow

curRow = curRow + 1
Next i

End Sub
Thanks. Any help is greatly appreciated.
 

Keetoowah

Member
Hi r121a947,
try this code, assuming you want to write the merged text in column B
Code:
Public Sub rejoinJ()
    
    Dim i As Long
    Dim lRow As Long
    Dim JoinedText As String
    
    lRow = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 1 To lRow
        
        JoinedText = WorksheetFunction.TextJoin(" ", True, Range("N" & i & ":BA" & i))
        Range("B" & i).Value = JoinedText '====> adapt the destination colum as needed

    Next i
    
End Sub
 
Top