View Single Post
 
Old 09-14-2022, 02:46 AM
a-friend a-friend is offline Windows 10 Office 2016
Novice
 
Join Date: Sep 2022
Posts: 3
a-friend is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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.
Hello
You are more than welcome. Thank you very much for the reply. I edited the thread. I have another Turkish file which has the identical data and I have no idea why they got merged in my mind. So I am sorry for making you confused and thank you for letting me know about it.
As for the code you offered, it just changes the contents' predefined white color into yellow and stops working.

The problem is that if it works, the code should include an exception too. (I guess I can bring it up here now.)

Some sentences either in English and in Persian have some 'notes' under them which should be attached to them. Probably, the code does not consider it and will put the say English note into a separate row and whereas there is no corresponding note for that in the right cell (including the Persian equivalent,) the right cell would be left empty and the code will keep going ahead doing its task. The problem is that when the whole work is done, there would be an extra work on these notes.

That said, in a single row, say the right cell might include 10 sentences, but the left cell can have less or more sentence in which the extra sentences are definitely the 'notes' which are preceded by their respective sentence.

The same goes with the Persian cells.

I was wondering how we can include this exception in the code?
Reply With Quote