Consulting

Results 1 to 6 of 6

Thread: 2 Column messagebox spacing of data

  1. #1
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location

    2 Column messagebox spacing of data

    I have a userform which shows data from 2 columns, due to the varing length of the names displayed, the second column info which is a constant length of characters.

    The info is displayed as the attached picture Messagebox. I would like the Expiry date info to always be on the right side of the messagebox as is on the attached Messagebox 2.

    Is this possible with my current code?

    Below is the code for the message box

    Sub Message()
    Dim msg As String, i As Long, a As Variant
        msg = ""
        
        For i = 1 To 2
            For Each a In Array("AC")
                msg = msg & Cells(i, a).Value & vbTab
            Next a
            msg = msg & vbCrLf
        Next i
        
        For i = 1 To 10
            For Each a In Array("U", "V")
                msg = msg & Cells(i, a).Value & vbTab
            Next a
            msg = msg & vbCrLf
        Next i
        
         For i = 1 To 10
            For Each a In Array("W", "X")
                msg = msg & Cells(i, a).Value & vbTab
            Next a
            msg = msg & vbCrLf
        Next i
        
        For i = 1 To 10
            For Each a In Array("Y", "Z")
                msg = msg & Cells(i, a).Value & vbTab
            Next a
            msg = msg & vbCrLf
        Next i
        
        For i = 1 To 10
            For Each a In Array("AA", "AB")
                msg = msg & Cells(i, a).Value & vbTab
            Next a
            msg = msg & vbCrLf
        Next I  
    End Sub
    Thanks for any advice or assistance
    Attached Images Attached Images

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    can you post your workbook?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    I have attached a sample work book, the information in the sheet is populated from another macro, but the attached shows some sample data.
    Attached Files Attached Files

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    perhaps...

    Sub vbax_61210()
    
        Dim i As Long, MaxLength As Long
        Dim msg As String
    
        MaxLength = Application.Max(Evaluate("=MAX(LEN(U2:U2000))"), Evaluate("=MAX(LEN(W2:W2000))"), Evaluate("=MAX(LEN(Y2:Y2000))"), Evaluate("=MAX(LEN(AA2:AA2000))"), Evaluate("=MAX(LEN(w:w))"))
    
        msg = Range("AC1").Value & vbTab & Range("AC2").Value & vbCrLf & vbCrLf
    
        For i = 1 To 10
            msg = msg & Range("U" & i) & Space(MaxLength - Len(Range("U" & i))) & vbTab & Range("V" & i) & vbCrLf
        Next i
        
        For i = 1 To 10
            msg = msg & Range("W" & i) & Space(MaxLength - Len(Range("W" & i))) & vbTab & Range("X" & i) & vbCrLf
        Next i
        
        For i = 1 To 10
            msg = msg & Range("Y" & i) & Space(MaxLength - Len(Range("Y" & i))) & vbTab & Range("Z" & i) & vbCrLf
        Next i
        
        For i = 1 To 10
            msg = msg & Range("AA" & i) & Space(MaxLength - Len(Range("AA" & i))) & vbTab & Range("AB" & i) & vbCrLf
        Next i
        
        MsgBox msg, , "Staff Information"
        
    End Sub
    you should consider displaying the text on a userform when the length of the string exceeds 1024 chars limit. and in your case it exceeds...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Thanks Mancubus for your assistance, I should be able to work with your solution, will mark this as solved.

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.

    thans for the feedback and marking the thread as solved.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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