Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-13-2022, 06:30 PM
Guessed's Avatar
Guessed Guessed is offline How to convert a single row into multiple in MS Word? Windows 10 How to convert a single row into multiple in MS Word? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Forgive my ignorance but ... Is 'Persian' and 'Turkish' being used interchangeably or are they different written languages and both appear in the tables?

You shouldn't iterate through the rows from top to bottom if you are modifying the row count as the loop proceeds. The loop should work from bottom to top.

My best guess as to what you are actually requiring is to modify the code this way. If this doesn't work, please post a small sample document that the code is supposed to work on?
Code:
Sub fnSplitCellsInNewTableRows()
  Dim oTable As Word.Table, iPars As Integer, intRow As Integer
  Dim rngParaLast As Range
  
  For Each oTable In ActiveDocument.Tables
    If oTable.Columns.Count = 2 And oTable.Uniform Then
      For intRow = oTable.Rows.Count To 1 Step -1
        With oTable.Rows(intRow)
          iPars = .Cells(1).Range.Paragraphs.Count
          If iPars = .Cells(2).Range.Paragraphs.Count Then
            If iPars > 1 Then
              Do While .Cells(1).Range.Paragraphs.Count > 1
                .Cells.Split NumRows:=2, NumColumns:=1, MergeBeforeSplit:=False
                Set rngParaLast = .Cells(1).Range.Paragraphs.Last.Range
                rngParaLast.MoveEnd Unit:=wdCharacter, Count:=-2
                oTable.Rows(intRow + 1).Cells(1).Range.FormattedText = rngParaLast.FormattedText
                rngParaLast.MoveEnd Unit:=wdCharacter, Count:=1
                rngParaLast.MoveStart Unit:=wdCharacter, Count:=-1
                rngParaLast.Delete

                Set rngParaLast = .Cells(2).Range.Paragraphs.Last.Range
                rngParaLast.MoveEnd Unit:=wdCharacter, Count:=-2
                oTable.Rows(intRow + 1).Cells(2).Range.FormattedText = rngParaLast.FormattedText
                rngParaLast.MoveEnd Unit:=wdCharacter, Count:=1
                rngParaLast.MoveStart Unit:=wdCharacter, Count:=-1
                rngParaLast.Delete
              Loop
            End If
          Else
            .Range.HighlightColorIndex = wdYellow
          End If
        End With
      Next intRow
    Else
      oTable.Range.HighlightColorIndex = wdBrightGreen    'highlite tables with merged cells or not 2 cols
    End If
  Next oTable
  
End Sub
The intention is that any time the inputs don't match, the table or rows will be highlighted.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert a single row into multiple in MS Word? Is there a way to Find multiple text strings in a Word document in a single operation? wrdy Word 8 04-03-2022 07:22 PM
Open Multiple Documents in Single Word 2010 Window? Clueless in Seattle Word 10 10-14-2020 08:37 AM
Search Multiple Strings and if Present get single word as output transactions Excel Programming 1 05-17-2019 11:18 AM
How to convert a single row into multiple in MS Word? Merging multiple excel records in to a single word doc? dns_to Mail Merge 1 10-20-2017 01:22 PM
How to convert a single row into multiple in MS Word? Copying Multiple tables from excel into a single word document dineshtgs Word Tables 1 04-07-2011 01:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:59 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