Hello! I have this macro that highlights in blue the text in the last column of the tables in the file if it exceeds the 100 characters. I would need to edit it so that the char count changes based on the text in the first column of each row. For example:
The macro does not highlight "Body text" because it sees "250 char" in the left column, sets the char count to 250 and and counts that "Body text" is shorter.
It goes to the next row and sees "20 char" in the left column, sets the char count to 20 for the right column and highlights the text.
This is the macro that I have now:
Can you help me? I get stuck with the left-right cell part.
Thanks!
The macro does not highlight "Body text" because it sees "250 char" in the left column, sets the char count to 250 and and counts that "Body text" is shorter.
It goes to the next row and sees "20 char" in the left column, sets the char count to 20 for the right column and highlights the text.
This is the macro that I have now:
VBA Code:
Sub HighlightLongRightColumnParagraphs()
Dim tbl As Table
Dim cell As Cell
Dim para As Paragraph
Dim charCount As Integer
charCount = 100
For Each tbl In ActiveDocument.Tables
' Get the last column index
Dim lastColIndex As Integer
lastColIndex = tbl.Columns.Count
' Loop through each cell in the last column
For Each cell In tbl.Columns(lastColIndex).Cells
For Each para In cell.Range.Paragraphs
If Len(para.Range.Text) > charCount Then
para.Range.HighlightColorIndex = wdTurquoise
End If
Next para
Next cell
Next tbl
End Sub
Can you help me? I get stuck with the left-right cell part.
Thanks!
Last edited by a moderator: