Avatar of thenelson
thenelson
 asked on

problem with last line of a table in Microsoft Word

Occasionally, the bottom gridline of a table in Microsoft Word disappears (see image below). bottom gridline missingI have tried many ways to correct this: reformat the table, add a line, etc but nothing works to get the gridline back.

When I use the following code:
Sub GetAvg()
Dim cellLoop As Cell, CellContents, datePreviousVisit, intColumnIndex As Integer

intColumnIndex = Selection.Cells(1).ColumnIndex
Selection.GoTo wdGoToBookmark, , , "VitalSigns"
Selection.MoveDown wdLine, 1
Selection.HomeKey wdLine
Selection.MoveRight wdWord, 5, wdExtend
If IsDate(Selection.Range.Text) Then
    datePreviousVisit = InputBox("Enter Fill date:", , CDate(Selection.Range.Text))
Else
    datePreviousVisit = InputBox("Enter Fill date:")
End If
If Len(datePreviousVisit & "") = 0 Then Exit Sub Else datePreviousVisit = CDate(datePreviousVisit)
'Debug.Print Format(datePreviousVisit, "mmm dd, yyyy")
For Each cellLoop In ActiveDocument.Tables(3).Columns(intColumnIndex).Cells
        CellContents = Split(Left(cellLoop.Range.Text, Len(cellLoop.Range.Text) - 2), ",")
        If UBound(CellContents) = 1 Then
            cellLoop.Range.Text = Trim(CellContents(0))
            If CellContents(1) = "" Then CellContents(1) = 0
            cellLoop.Range.Text = Trim(CellContents(0)) & ", " & Trim(CellContents(1)) & ", " & Trim(Round((cellLoop.Range.Calculate - CellContents(1)) / DateDiff("d", datePreviousVisit, ActiveDocument.Bookmarks("DOS").Range.Text), 1))
        End If
Next cellLoop
ActiveDocument.Tables(3).Cell(1, intColumnIndex).Select
End Sub

Open in new window

with the missing gridline, I get this error message: "run time error 5992; Cannot access individual columns  in this collection because the table has mixed cell widths."

Is there a way to get the gridline back or a way to change the code so it runs with the missing gridline?

Thanks
VBAMicrosoft Word* tables

Avatar of undefined
Last Comment
ITSysTech

8/22/2022 - Mon
ITSysTech

If you click on an effected cell what does "Text Direction" show?

1.JPG
ITSysTech

Also, try changing the alignment to "Top".

1.JPG
thenelson

ASKER
Text direction is normal:text direction
Alignment is already set to top:
alignment.png
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ITSysTech

There must be something causing this like a photo or your header. Have you tried to rearrange images on your document if you have any?
thenelson

ASKER
There are no images.  This problem usually (but not always) occurs when I copy and paste the table from another Word document.
ASKER CERTIFIED SOLUTION
ITSysTech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ITSysTech

Inactive for 14 days
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.