Aligning Multiple Columns in Msgbox

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,345
Office Version
  1. 365
Platform
  1. Windows
I know I can probably do this with a userform but don't really want to mess around with recoding at this point.

I have a routine that eventually outputs something like the msgbox displayed below. The only problem is my tabulated spacing gets messed up when one of my words is too long (as shown in my example). Can anyone think of a workaround to address this?

Code:
Sub Example()

MsgBox ("Zoo" & vbTab & vbTab & 10 & vbTab & "1.0%" & vbNewLine & _
        "Exhibition" & vbTab & vbTab & 3 & vbTab & "1.9%" & vbNewLine & _
        "Popular" & vbTab & vbTab & 4 & vbTab & "1.7%" & vbNewLine & _
        "Manchester" & vbTab & vbTab & 9 & vbTab & "0.6%" & vbNewLine)
     
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I used 20 arbitrarily here, but anything exceeding the length of the longest individual string in your message should work. Not a pretty solution, but may serve until someone offers something better.
Code:
Sub Example()

MsgBox ("Zoo" & String(20 - Len("Zoo"), " ") & vbTab & vbTab & 10 & vbTab & "1.0%" & vbNewLine & _
        "Exhibition" & String(20 - Len("Exhibition)"), " ") & vbTab & vbTab & 3 & vbTab & "1.9%" & vbNewLine & _
        "Popular" & String(20 - Len("Popular"), " ") & vbTab & vbTab & 4 & vbTab & "1.7%" & vbNewLine & _
        "Manchester" & String(20 - Len("Manchester"), " ") & vbTab & vbTab & 9 & vbTab & "0.6%" & vbNewLine)
     
End Sub
 
Upvote 0
Thanks Joe. I can definitely work with that! I'm curious if anyone has any other methods :)
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top