Alignment in Word is a paragraph (not line) attribute. So unless each line is a paragraph, there isn't much you can do. If each line is a paragraph, and as the text with "XX" is already left aligned then all you need is:
Sub ScratchMacro() ' A basic Word macro coded by Greg Maxey Dim oPar As Paragraph For Each oPar In ActiveDocument.Paragraphs If InStr(oPar.Range.Text, "YY") Then oPar.Alignment = wdAlignParagraphRight Next oPar lbl_Exit: Exit Sub End Sub