View Single Post
 
Old 06-13-2022, 05:59 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It seems to me you're trying to deal with the problem from the wrong end. It would be far simpler to correct the data before merging. Try the following macro on your source document:
Code:
Sub SourceTableReformat()
Application.ScreenUpdating = False
Dim r As Long, x As Long, y As Long, Rng As Range, StrTxt As String
With ActiveDocument.Tables(1)
  For r = .Rows.Count To 2 Step -1
    With .Rows(r)
      StrTxt = Split(.Cells(4).Range.Text, vbCr)(0)
      x = UBound(Split(StrTxt, ","))
      If x > 0 Then
        Set Rng = .Range
        For y = 1 To x - 1
          Rng.Collapse wdCollapseEnd
          Rng.FormattedText = .Range.FormattedText
          Rng.Cells(4).Range.Text = Trim(Split(StrTxt, ",")(y))
        Next
        .Cells(4).Range.Text = Trim(Split(StrTxt, ",")(0))
      End If
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote