Solved

Formatting in a message box

Posted on 2013-11-19
3
161 Views
Last Modified: 2013-11-19
Folks,
The below code works fine but I need a little tweaking. If B9 = $2,500 and D9 = $5,000 I like the formatting of difference to be in dollars, 2 decimal places. The cells are formatted as currency 2 decimals already. I am getting the right answer but would like it formatted in dollars and cents please.

Private Sub cmdInvestmentA_Click()
If Range("B9") < Range("D9") Then
MsgBox "Correct because the total cash outlay is " & Range("B9")  - Range("D9") & " less!"
Else
MsgBox "Incorrect because the total cash out is " & Range("D9") - Range("B9")  & " more!"
End If
End Sub

Open in new window

0
Comment
Question by:Frank Freese
3 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39660357
Try

Private Sub cmdInvestmentA_Click()
If Range("B9") < Range("D9") Then
MsgBox "Correct because the total cash outlay is $" & _
        Format(Range("B9") - Range("D9"), "#,##0.00") & _
        " less!"
Else
MsgBox "Incorrect because the total cash out is $" & _
        Format(Range("D9") - Range("B9"), "#,##0.00") & _
        " more!"
End If
End Sub
0
 
LVL 6

Expert Comment

by:ButlerTechnology
ID: 39660362
You can use the Format function - Format(Range("a1"), "$00.00").

Tom
0
 

Author Closing Comment

by:Frank Freese
ID: 39660385
thank you
that nailed it.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
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…

813 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

12 Experts available now in Live!

Get 1:1 Help Now