Vertically align multiline string

  • I am trying to create a multiline string and print it out with the following code.

    The output is attached below.

    How do I create a string where the text is vertically aligned so that Testing3 is precisely below Testing2?

    Is there a suitable formula for the number of spaces before Testing3?

  • Hello,

    You can test the following

    Sub OutputText()
    Dim string1 As String
    Dim string2 As String
    Dim i As Long
    string1 = "Testing1" & Space(4) & "Testing2"
    string2 = "Testing3"
    i = Len(string1) - Len(string2) - (Len(string2) / 2)
    string1 = string1 & vbNewLine & vbNewLine & Space(i) & string2
    MsgBox (string1)
    End Sub

    Hope this will help


    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!