If not Found then Input

S

Steved

Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and R 0:0:0
Please how do I tell the macro that Example is right and move onto the next
and so on, now if eample 2 is found then input L 0:0:0 above the R 22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in Example 4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub
 
D

Doug Robbins - Word MVP

Use

Dim myrange As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
myrange.InsertBefore "R 0:0:0" & vbCr
End If
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
myrange.InsertBefore "L 0:0:0" & vbCr
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and R
0:0:0
Please how do I tell the macro that Example is right and move onto the
next
and so on, now if eample 2 is found then input L 0:0:0 above the R
22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in Example
4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub
 
S

Steved

Hello Doug from Steved
Thankyou

Doug Please could I have in example 2 a input off "L 0:0:0" above the R
22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0" inbetween SPR
and F 0:0:0

In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your coding
and I Thankyou.

Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12





Doug Robbins - Word MVP said:
Use

Dim myrange As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
myrange.InsertBefore "R 0:0:0" & vbCr
End If
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
myrange.InsertBefore "L 0:0:0" & vbCr
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and R
0:0:0
Please how do I tell the macro that Example is right and move onto the
next
and so on, now if eample 2 is found then input L 0:0:0 above the R
22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in Example
4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub
 
D

Doug Robbins - Word MVP

That is exactly what the code does when I run it.

Starting with a document containing:

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
F 9:11:7¶
SPR¶
F 0:0:0¶

after running the macro, I get

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
L 0:0:0¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
R 0:0:0¶
F 9:11:7¶
SPR¶
L 0:0:0¶
R 0:0:0¶
F 0:0:0¶

Are you sure that each item is in a separate paragraph as indicated by the ¶
that I have inserted above.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello Doug from Steved
Thankyou

Doug Please could I have in example 2 a input off "L 0:0:0" above the R
22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0" inbetween
SPR
and F 0:0:0

In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
coding
and I Thankyou.

Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12





Doug Robbins - Word MVP said:
Use

Dim myrange As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
myrange.InsertBefore "R 0:0:0" & vbCr
End If
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
myrange.InsertBefore "L 0:0:0" & vbCr
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and R
0:0:0
Please how do I tell the macro that Example is right and move onto the
next
and so on, now if eample 2 is found then input L 0:0:0 above the R
22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
Example
4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub
 
S

Steved

Hello Doug from Steved.

It's perfect I thankyou.

Please I would like to explain what had happened.

Because off you code and I like to learn what you code does I run it in
"Step Mode".
The first 3 it had done was fine then on the 4th the R 0:0:0 was missing you
code inputted it which is what it is supposed to do but when it found L 0:0:0
missing it ignored it by not inserting L 0:0:0 and went onto the next one,
however when I run your macro ( not step mode ) it did inputted it.

ps Yes Doug I should have run the macro, I'm very sorry for wasting your
time, as I should have know'n better.

Thankyou for your good work.

Doug Robbins - Word MVP said:
That is exactly what the code does when I run it.

Starting with a document containing:

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
F 9:11:7¶
SPR¶
F 0:0:0¶

after running the macro, I get

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
L 0:0:0¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
R 0:0:0¶
F 9:11:7¶
SPR¶
L 0:0:0¶
R 0:0:0¶
F 0:0:0¶

Are you sure that each item is in a separate paragraph as indicated by the ¶
that I have inserted above.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello Doug from Steved
Thankyou

Doug Please could I have in example 2 a input off "L 0:0:0" above the R
22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0" inbetween
SPR
and F 0:0:0

In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
coding
and I Thankyou.

Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12





Doug Robbins - Word MVP said:
Use

Dim myrange As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
myrange.InsertBefore "R 0:0:0" & vbCr
End If
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
myrange.InsertBefore "L 0:0:0" & vbCr
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and R
0:0:0
Please how do I tell the macro that Example is right and move onto the
next
and so on, now if eample 2 is found then input L 0:0:0 above the R
22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
Example
4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub
 
D

Doug Robbins - Word MVP

No problem. It was really your time that you wasted.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello Doug from Steved.

It's perfect I thankyou.

Please I would like to explain what had happened.

Because off you code and I like to learn what you code does I run it in
"Step Mode".
The first 3 it had done was fine then on the 4th the R 0:0:0 was missing
you
code inputted it which is what it is supposed to do but when it found L
0:0:0
missing it ignored it by not inserting L 0:0:0 and went onto the next one,
however when I run your macro ( not step mode ) it did inputted it.

ps Yes Doug I should have run the macro, I'm very sorry for wasting your
time, as I should have know'n better.

Thankyou for your good work.

Doug Robbins - Word MVP said:
That is exactly what the code does when I run it.

Starting with a document containing:

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
F 9:11:7¶
SPR¶
F 0:0:0¶

after running the macro, I get

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
L 0:0:0¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
R 0:0:0¶
F 9:11:7¶
SPR¶
L 0:0:0¶
R 0:0:0¶
F 0:0:0¶

Are you sure that each item is in a separate paragraph as indicated by
the ¶
that I have inserted above.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello Doug from Steved
Thankyou

Doug Please could I have in example 2 a input off "L 0:0:0" above the R
22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0"
inbetween
SPR
and F 0:0:0

In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
coding
and I Thankyou.

Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12





:

Use

Dim myrange As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R"
Then
myrange.InsertBefore "R 0:0:0" & vbCr
End If
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L"
Then
myrange.InsertBefore "L 0:0:0" & vbCr
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and
R
0:0:0
Please how do I tell the macro that Example is right and move onto
the
next
and so on, now if eample 2 is found then input L 0:0:0 above the R
22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
Example
4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub
 
S

Steved

Thankyou Doug

Doug Robbins - Word MVP said:
No problem. It was really your time that you wasted.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Steved said:
Hello Doug from Steved.

It's perfect I thankyou.

Please I would like to explain what had happened.

Because off you code and I like to learn what you code does I run it in
"Step Mode".
The first 3 it had done was fine then on the 4th the R 0:0:0 was missing
you
code inputted it which is what it is supposed to do but when it found L
0:0:0
missing it ignored it by not inserting L 0:0:0 and went onto the next one,
however when I run your macro ( not step mode ) it did inputted it.

ps Yes Doug I should have run the macro, I'm very sorry for wasting your
time, as I should have know'n better.

Thankyou for your good work.

Doug Robbins - Word MVP said:
That is exactly what the code does when I run it.

Starting with a document containing:

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
F 9:11:7¶
SPR¶
F 0:0:0¶

after running the macro, I get

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
L 0:0:0¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
R 0:0:0¶
F 9:11:7¶
SPR¶
L 0:0:0¶
R 0:0:0¶
F 0:0:0¶

Are you sure that each item is in a separate paragraph as indicated by
the ¶
that I have inserted above.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hello Doug from Steved
Thankyou

Doug Please could I have in example 2 a input off "L 0:0:0" above the R
22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0"
inbetween
SPR
and F 0:0:0

In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
coding
and I Thankyou.

Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12





:

Use

Dim myrange As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R"
Then
myrange.InsertBefore "R 0:0:0" & vbCr
End If
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L"
Then
myrange.InsertBefore "L 0:0:0" & vbCr
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and
R
0:0:0
Please how do I tell the macro that Example is right and move onto
the
next
and so on, now if eample 2 is found then input L 0:0:0 above the R
22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
Example
4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top