?
Solved

Accounting format

Posted on 2012-12-29
4
Medium Priority
?
265 Views
Last Modified: 2012-12-30
I have a message box that puts out 2 lines of currency values (along with text).  

Is there any way to format the currency so it aligns by decimal? (Accountant format)
0
Comment
Question by:thandel
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 38730350
0
 
LVL 50

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 38730367
That won't work because the MsgBox doesn't normally use a monospaced font; in other words each number or letter may be of different widths. It might be possible to subclass the msgbox so that it does use a monospaced font but even if that allowed you to align the decimals with something like this (which doesn't work because of the font problem) it would be ugly because monospaced fonts are IMO ugly.

    Dim Amt1 As String
    Dim Amt2 As String
    Dim FormatString1 As String
    Dim FormatString2 As String
    
    Amt1 = 20000.19
    Amt2 = 5125.12
    
    FormatString1 = "0123456789" ' Initialize string.
    FormatString2 = "0123456789" ' Initialize string.
    
    RSet FormatString1 = Amt1
    RSet FormatString2 = Amt2
    
    Debug.Print FormatString1
    Debug.Print FormatString2
    
    MsgBox FormatString1 & vbCrLf & FormatString2

Open in new window


I think the only choice you have is to accept the ugliness and use a UserForm that contains a label along with this code

Private Sub UserForm_Initialize()
    Dim Amt1 As String
    Dim Amt2 As String
    Dim FormatString1 As String
    Dim FormatString2 As String
    
    Amt1 = 20000.19
    Amt2 = 5125.12
    
    FormatString1 = "0123456789" ' Initialize string.
    FormatString2 = "0123456789" ' Initialize string.
    
    RSet FormatString1 = Amt1
    RSet FormatString2 = Amt2
    
    Debug.Print FormatString1
    Debug.Print FormatString2
    
    Label1.Font = "courier"
    Label1.Caption = "This is ugly but it aligns" & vbCrLf & vbCrLf & FormatString1 & vbCrLf & FormatString2

End Sub

Open in new window


If you do you'll get this:
Ugly but aligned
0
 

Author Closing Comment

by:thandel
ID: 38730721
Thanks for the clear code and example.
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 38731007
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question