I've tried researching on Google on how to find the last cell in a column of a Word table but have been unable to find anything.
When I run my TextToTable code, I would like to change the semi colon in the very last cell of Column 2 to a period/full stop but unsure how to add this to my existing code. Can anyone help at all?
Capture.JPG
Code:
Sub TextToTables()
Dim rRng As Range, rCell As Range 'Convert text to table
Dim oBorder As Border
Dim oTbl As Table
Dim i As Integer
Application.ScreenUpdating = False
Set rRng = ActiveDocument.Range
Set oTbl = rRng.ConvertToTable(Separator:=wdSeparateByTabs, NumColumns:=2, AutoFitBehavior:=wdAutoFitFixed)
With oTbl
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.Columns.PreferredWidth = InchesToPoints(2.7)
.Columns(2).PreferredWidth = InchesToPoints(3.63)
For Each oBorder In .Borders
oBorder.LineStyle = wdLineStyleNone
Next oBorder
Call DPU_ApplyDefinitionStylesToTable
For i = 1 To .Rows.count 'check each row
Set rCell = .Cell(i, 1).Range 'set a range to the cells in column 1
rCell.Style = "DefBold" 'apply the style to the range
Set rCell = .Cell(i, 2).Range 'set a range to the cells in column 2
rCell.Collapse 1 'collapse the range to its start
rCell.MoveEndWhile "means,:" 'move the end of the range to include any of these characters
If rCell.text Like "means*" Then 'if that range starts with 'means'
rCell.MoveEndWhile Chr(32) 'move the end of the range to include any following spaces
rCell.text = "" 'and empty the range
End If
Next i
End With
Application.ScreenUpdating = True
Set rRng = Nothing
Set oTbl = Nothing
Set rCell = Nothing
Set oBorder = Nothing
End Sub