Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2021, 12:50 AM
WJSwanepoel WJSwanepoel is offline Split table cell into multiple rows based on a delimiter Windows 10 Split table cell into multiple rows based on a delimiter Office 2007
Advanced Beginner
Split table cell into multiple rows based on a delimiter
 
Join Date: Dec 2019
Posts: 30
WJSwanepoel is on a distinguished road
Default Split table cell into multiple rows based on a delimiter

I have a table where I want to select a cell and split it into multiple rows based on a delimiter (e.g. a paragraph mark).



What is the best way to achieve this with the minimum effort?

I use Word 2007.

I found one way of getting it done, but it loses certain formatting which has to be redone, e.g. Paragraph indenting.
If I copy the table to Excel it will automatically put the lines ending in a paragraph mark in separate rows. I then copy the Excel table back to Word and then reformat it. I would however prefer an automated way since my documents contain many (hundreds) such tables.
Attached Files
File Type: docx CellSplit.docx (16.4 KB, 2 views)

Last edited by WJSwanepoel; 01-26-2021 at 10:14 PM. Reason: Additional information
Reply With Quote
  #2  
Old 01-28-2021, 04:45 AM
macropod's Avatar
macropod macropod is offline Split table cell into multiple rows based on a delimiter Windows 10 Split table cell into multiple rows based on a delimiter Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,821
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

For example:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, r As Long, c As Long, Rng As Range
For Each Tbl In ActiveDocument.Tables
  With Tbl
    For r = .Rows.Count To 1 Step -1
      Do While .Cell(r, 1).Range.Paragraphs.Count > 1
        If r < .Rows.Count Then
          .Rows.Add BeforeRow:=.Rows(r + 1)
        Else
          .Rows.Add
        End If
          For c = 1 To .Columns.Count
            Set Rng = .Cell(r, c).Range.Paragraphs.Last.Range
            Rng.End = Rng.End - 1
            With .Cell(r + 1, c).Range.Paragraphs.Last.Range
              .ParagraphFormat = Rng.ParagraphFormat
              .FormattedText = Rng.FormattedText
            End With
            Rng.Start = Rng.Start - 1
            Rng.Delete
          Next
      Loop
    Next
  End With
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-28-2021, 09:13 PM
WJSwanepoel WJSwanepoel is offline Split table cell into multiple rows based on a delimiter Windows 10 Split table cell into multiple rows based on a delimiter Office 2007
Advanced Beginner
Split table cell into multiple rows based on a delimiter
 
Join Date: Dec 2019
Posts: 30
WJSwanepoel is on a distinguished road
Default Resolved

Good day Paul,
Thank you very, very much for the assistance.

I tested your code on one of my files, and it works 100% correctly! I will flag the thread as resolved.

Regards,
Willem Swanepoel
Reply With Quote
  #4  
Old 02-02-2021, 10:26 PM
WJSwanepoel WJSwanepoel is offline Split table cell into multiple rows based on a delimiter Windows 10 Split table cell into multiple rows based on a delimiter Office 2007
Advanced Beginner
Split table cell into multiple rows based on a delimiter
 
Join Date: Dec 2019
Posts: 30
WJSwanepoel is on a distinguished road
Default One more question

If I wanted to change any other properties, eg. Font, how would I be able to do that?
Reply With Quote
  #5  
Old 02-02-2021, 10:33 PM
macropod's Avatar
macropod macropod is offline Split table cell into multiple rows based on a delimiter Windows 10 Split table cell into multiple rows based on a delimiter Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,821
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

That all depends on what/when you want to make those changes. I suggest you start a new thread for that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Split table cell into multiple rows based on a delimiter split table rows based Dynamic values generated for row Naveen Dhanaraj Word Tables 10 03-06-2020 03:23 AM
Split table cell into multiple rows based on a delimiter Split an excel file into multiple files based on a column's content puff Excel 1 07-04-2018 08:35 AM
creating multiple data rows, for labels based on a cell value josbor01 Excel Programming 3 01-02-2018 02:04 PM
Split table cell into multiple rows based on a delimiter Split file using variable delimiter kramer74 Word VBA 7 09-01-2014 12:12 AM
How to auto-split a table at FULL rows? pstein Word 5 03-27-2012 02:48 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 03:47 PM.


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