#1
|
|||
|
|||
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. Last edited by WJSwanepoel; 01-26-2021 at 10:14 PM. Reason: Additional information |
#2
|
||||
|
||||
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] |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
One more question
If I wanted to change any other properties, eg. Font, how would I be able to do that?
|
#5
|
||||
|
||||
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] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
split table rows based Dynamic values generated for row | Naveen Dhanaraj | Word Tables | 10 | 03-06-2020 03:23 AM |
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 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 |