VBA formatting output of array to msgbox/userform

Miro H

New Member
Joined
Mar 25, 2015
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have this simple code that I planned to use for formatting output of array to msgbox or userform.

I want to have output formatted in rows and columns.

This is a code:

VBA Code:
For i = 1 To nr
    For j = 1 To nc
        k = Len(arrUpdateResult(i, j))
        strResult = strResult & arrUpdateResult(i, j) & Space(25-k)
    Next j
    strResult = strResult & vbCrLf
Next i

msgbox strResult
ufUserForm.lblLabel1.Caption = strResult

Array type is variant, I have name, numbers and dates.

I can't figure out why the output is not working properly. It is not completely messed up but it is not lined up correctly.

This part of code should have variable spaces between words and word + spaces should always have same number of characters - 25
VBA Code:
k = Len(arrUpdateResult(i, j))
strResult = strResult & arrUpdateResult(i, j) & Space(25-k)

I also tried with vbtab, but it doesn't give me good results as well, because if some strings are much shorter tab does not work properly.

What am I doing wrong? How can I format output in columns?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
There is nothing wrong with the code, but it's very difficult to make everything line when using proportionally spaced fonts.
If you change the Label font on the userform to a monospaced font, like Courier, it should work.
 
Upvote 0
I changed the font and now it works. Quick and simple.

I've spent at least an hour trying to figure out what is wrong.

Thank you very much.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

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