Consulting

Results 1 to 5 of 5

Thread: Align a line based on a value in the line

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Oct 2019
    Posts
    1
    Location

    Question Align a line based on a value in the line

    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
    Last edited by Aussiebear; 01-10-2025 at 01:28 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •