Solved

Formatting in a message box

Posted on 2013-11-19
3
142 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
Comment Utility
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
Comment Utility
You can use the Format function - Format(Range("a1"), "$00.00").

Tom
0
 

Author Closing Comment

by:Frank Freese
Comment Utility
thank you
that nailed it.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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. …
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

763 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

6 Experts available now in Live!

Get 1:1 Help Now