View Single Post
 
Old 12-24-2023, 07:29 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default

Thank you, Gmayor! I'll keep your code for more complex strings. Actually my case is not so complex, so I've rewritten my code as follows (thank you, Vivka!!):
Code:
Sub LastNameRN()
Set oRng = ActiveDocument.Paragraphs(1).Range
   If InStr(1, oRng, ",") > 0 Then
      oRng.Collapse
      oRng.MoveStartUntil Cset:=","
      oRng.Previous(unit:=wdWord, Count:=1).Select
   Else
      oRng.Words.Last.Previous(unit:=wdWord, Count:=1).Select
   End If
End Sub
Reply With Quote