Solved

Accounting format

Posted on 2012-12-29
4
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 38730350
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 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 47

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

749 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