Hi,
As part of a project I am working I am attempting to split a table into a series of separate tables based on a comparison of the first four characters within a column of cells.
A separate problem to do with formatting text in the same project is discussed
here
The code below is extracted from the wider project which copies a pivot table from excel into word and formats it for a report.
The first column of the table contains a reference number which is formatted 6.X.X . Depending on the length of the report this number may end up being 6.XX.X . I would like to split the table into separate tables at every row in which the numbers between the bullet points change.
eg 6.1.1, 6.1.2, 6.1.3, Table split, 6.2.1, 6.2.2, table split, 6.3.1, etc
An image of the table is attached below
Table eg3.JPG
Currently the code I have put together splits the table at all rows within the table and try as I might I don't seem to be setting the ranges for comparison correctly.
Code:
Dim eRow As Row
Dim A As Long
Dim WordTable As Word.Table
Dim RefRange1 As Word.Range
Dim RefRange2 As Word.Range
Dim TxtRange1 As Word.Range
Dim TxtRange2 As Word.Range
A = 1
Do While A > 0
On Error Resume Next
For Each eRow In WordTable.Rows
Set RefRange1 = eRow.Cells(1).Range
Set RefRange2 = RangeRef1.Rows(-1).Cells(1).Range
Set TxtRange1 = RefRange1.Cells(1).Range.Characters(1)
TxtRange1.End = RefRange1.Cells(1).Range.Characters(4)
Set TxtRange2 = RefRange2.Cells(1).Range.Characters(1)
TxtRange1.End = RefRange2.Cells(1).Range.Characters(4)
If TxtRange1.IsEqual(Range:=TxtRange2) = False Then
A = eRow.Cells(1).RowIndex
End If
Next
If A = 1 Then Exit Do
WordTable.Split (A)
A = 1
Loop
Any help or guidance would be greatly appreciated.
Thanks
Thom