PDA

View Full Version : Tables - Find String, Insert Text, Insert Section Break



JinkyJulie
04-21-2015, 06:06 AM
Hello again everybody, :hi:

Here I am again with another word table problems :banghead:... I hope I can explain what I am trying to do...



Find each instance of a string (in Col 4), let us say "Banana", in the entire table (4 columns, n rows)
When an instance found, enter string, "Split" in Col 3 (same row)
Split the table up (section breaks) at every second instance of "Split"


As there should be twenty instances of "Banana", I should end up with ten separate tables

I have split tables up before, but it is really the search and add text that is getting me.

I will really appreciate a push in the right direction...

Thanking you all again for the push...

JJ

gmaxey
04-21-2015, 06:03 PM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Dim lngIndex As Long
Set oRng = Selection.Tables(1).Range
With oRng.Find
.Text = "XX"
While .Execute
lngIndex = lngIndex + 1
If oRng.Information(wdEndOfRangeColumnNumber) = 4 Then
oRng.Cells(1).Previous.Range.Text = "Split"
If lngIndex = 2 Then
oRng.Tables(1).Split oRng.Rows(1)
lngIndex = 1
End If
oRng.Collapse wdCollapseEnd
End If
Wend
End With
End Sub