View Single Post
 
Old 03-29-2022, 07:58 AM
ericliu24 ericliu24 is offline Windows 10 Office 2019
Novice
 
Join Date: Mar 2022
Location: China
Posts: 21
ericliu24 is on a distinguished road
Default How to combine the texts of all cells in a column without line break.

I try to combine the texts of all cells in a column into a paragraph.

For example:

Table is like :

1 this
2 is
3 great

I would like to get "this is great".

But my code below always return
" this
is
great"

Could you please help me out. Many thanks.

Code:
Sub TEST1()
Dim c As Long
Dim String1 As String

With ActiveDocument.Tables(1)
For r = 1 To .Rows.Count
String1 = String1 & .Cell(r, .Columns.Count).Range.Text
'Debug.Print String1
Next r

End With

With ActiveDocument.SelectContentControlsByTitle("text1")(1)

     '.LockContentControl = False
     .Range.Text = String1
     '.LockContentControl = True
    End With
End Sub
Reply With Quote