T
tbaam
What am I doing wrong?
I looked at old posts and wrote the following piece of code. It searches a
table for a section of rows and keeps them together. I then want then to stay
together and if necessary go to the next page.
I can the see the lines highlight as expected but the paragraph format does
not seem to be doing what it is suppose to.
Thanks
Sub Macro1()
Dim i
Dim End_row, Start_row, New_row As Integer
Dim num
'num = Selection.Columns(1).Cells.Count
Row = 3
For i = 4 To 400
Value = Left(ActiveDocument.Tables(2).Cell(Row:=i,
Column:=1).Range.Text, Len(ActiveDocument.Tables(2).Cell(Row:=i,
Column:=1).Range.Text) - 2)
If Value < 100 Then
End_row = i
With ActiveDocument.Tables(2)
pos = .Cell(Row, 1).Range.Start
posEnd = .Cell(End_row, 5).Range.End
Set myrange = ActiveDocument.Range(Start:=pos, End:=posEnd)
myrange.Select
'Selection.myrange
With Selection.ParagraphFormat
.WidowControl = True
.KeepWithNext = True
.KeepTogether = True
.PageBreakBefore = False
End With
End With
Row = i
End If
Next i
End Sub
I looked at old posts and wrote the following piece of code. It searches a
table for a section of rows and keeps them together. I then want then to stay
together and if necessary go to the next page.
I can the see the lines highlight as expected but the paragraph format does
not seem to be doing what it is suppose to.
Thanks
Sub Macro1()
Dim i
Dim End_row, Start_row, New_row As Integer
Dim num
'num = Selection.Columns(1).Cells.Count
Row = 3
For i = 4 To 400
Value = Left(ActiveDocument.Tables(2).Cell(Row:=i,
Column:=1).Range.Text, Len(ActiveDocument.Tables(2).Cell(Row:=i,
Column:=1).Range.Text) - 2)
If Value < 100 Then
End_row = i
With ActiveDocument.Tables(2)
pos = .Cell(Row, 1).Range.Start
posEnd = .Cell(End_row, 5).Range.End
Set myrange = ActiveDocument.Range(Start:=pos, End:=posEnd)
myrange.Select
'Selection.myrange
With Selection.ParagraphFormat
.WidowControl = True
.KeepWithNext = True
.KeepTogether = True
.PageBreakBefore = False
End With
End With
Row = i
End If
Next i
End Sub