PDA

View Full Version : Split Table based on Value



hogg
11-13-2008, 06:40 AM
Hey!

Thanks for all the help recently but I've got another problem which I can't solve!:dunno

I need to look up a value in a table and split the table where the value occours. There are several cells with the same text. I think I'm close to a solution but I'm missing a vital line or two of code! What happens at the moment is the value is found, replaced with a table split and then the same value is founds again! I've tried replaceing the text before the table split but the document just crashes becuse it keeps replacing the same text!

heres what I've got:


Sub Lookup_replace()


Do Until ActiveDocument.Bookmarks("\Sel") = _
ActiveDocument.Bookmarks("\EndOfDoc")
Selection.Find.ClearFormatting
With Selection.Find
.Text = "R.Replace"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

If Selection.Find.Found = True Then

Selection.Find.Replacement.Text = " "
Selection.SplitTable

Else
Exit Do
End If
Loop
End Sub

What am I missing?

Thanks for your help!

hogg
11-13-2008, 10:14 AM
Ok I worked it out. I needed to add:
Selection.Find.Execute
To tell the program to move on after it split the table. This code is a blunt way to achieve the problem I'm having here:
http://www.vbaexpress.com/forum/showthread.php?t=23468
which will have to do until I can find a better solution!

(I still can't mark these posts as solved...:( )