Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 06-13-2022, 05:59 PM
macropod's Avatar
macropod macropod is offline Split Data from Mergefield into seperate rows Windows 10 Split Data from Mergefield into seperate rows Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split Data from Mergefield into seperate rows Delete blank table rows in merged document and split document in docx and pdf based on excel rows Alex1s85 Word VBA 5 05-22-2021 12:05 PM
Split data in cells and duplicate rows ballpoint Excel Programming 6 02-07-2018 05:52 PM
Split Data from Mergefield into seperate rows Blank Rows in Table populated through Conditional IF statemement MergeField options in Word gideonpm Mail Merge 3 12-22-2016 01:20 PM
Macro Winword mailmerge split printpage with mergefield as filename pca Word VBA 2 02-28-2014 02:43 PM
Can I do this? sorting data in seperate columns shumonsaha Excel 0 07-04-2010 03:05 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft