Solved

Formatting in a message box

Posted on 2013-11-19
3
172 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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.

762 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