I have a text file with over 50,000 rows (lines).
There's a character in each line - say 'XX' and 'YY', which doesn't occur otherwise


For each line with 'XX', I want the line to be left aligned, and for 'YY' I need it right aligned. (As of now, all the lines are left aligned.)
There's no particular sequence in XX or YY type repetition. (XX and YY type lines occur randomly.) And at each change from XX to YY or vice versa, I need a new line character.


Let me clarify this with an example.

Data:

    (Left-aligned) XX: ABCD
    (Left-aligned) YY: EFGH
    (Left-aligned) YY: IJK
    (Left-aligned) XX: LMN
    (Left-aligned) XX: OPQ
    (Left-aligned) YY: STU

Output Required:


    (Left-aligned) XX: ABCD


    (Right-aligned) YY: EFGH
    (Right-aligned) YY: IJK


    (Left-aligned) XX: LMN
    (Left-aligned) XX: OPQ


    (Right-aligned) YY: STU
I tried with this but it doesn't give desired result. Please guide me to fix the code to get the result.

Private Sub alignText()
    With Selection.Find.Execute FindText:="YY", Forward:=True
         Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
    End With
End Sub