Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Formatting in a message box

Posted on 2013-11-19
3
Medium Priority
?
194 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

824 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