Solved

Formatting in a message box

Posted on 2013-11-19
3
175 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
[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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

734 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