Solved

Accounting format

Posted on 2012-12-29
4
253 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
Comment Utility
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
Thanks for the clear code and example.
0
 
LVL 45

Expert Comment

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

Marty - MVP 2009 to 2012
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now