We help IT Professionals succeed at work.

Word VBA

I have a string of text.  Somewhere in that string there's a < (greater than character ).  I would like to delete everthing from my current cursor position to the greater than character.
 My cursor is at the beginning of the line
 What is the VBA code to do this?
Comment
Watch Question

Top Expert 2016
Commented:
HI,

pls try ( greater is >, if not what you want pls correct code)

Set myRange = Selection.Paragraphs(1).Range
myRange.Text = Mid(myRange.Text, InStr(1, myRange.Text, ">") + 1)

Open in new window

Regards

Author

Commented:
Hi Rgonzo:
Does the plus sign connect with anything?  I'm getting red when I paste that into my VBE
GrahamSkanRetired
Top Expert 2012

Commented:
I think this should do it:
Sub DelTillGT()
    Dim rng As Range
    
    Set rng = Selection.Range.Duplicate
    
    rng.End = ActiveDocument.Range.End
    With rng.Find
        .Text = "*\>"
        .MatchWildcards = True
        .Replacement.Text = ""
        .Execute Replace:=wdReplaceOne
    End With
End Sub

Open in new window

GrahamSkanRetired
Top Expert 2012

Commented:
brothertruffle880,
Have you missed off the end of Rgonzo's code?

Author

Commented:
Here's an example of what I want (apologies for earllier typo.  I should have said LESS THAN sign, not GREATER THAN
Candy Apple < Needed text1
Chocolate Apple < needed text2
Vanilla Apple < needed text3
At the end of the process, I want to have the following:
needed text1
needed text2
needed text3
I want everything deleted from the beginning of each line up to the less than sign.

I have a string of text.  Somewhere in that string there's a < (less than character ).  I would like to delete everthing from my current cursor position to the greater than character.
  My cursor is at the beginning of the line
  What is the VBA code to do this?

Author

Commented:
Holy cow Rgonzo!   Your posting corrected itself.
Now I see the entire thing!  
A few minutes ago there was a dangling plus sign at te end of the code.  
Let me try the clean post I just saw.

Author

Commented:
Rgonzo.  It worked.  Thanks!