Evaluating two cells with VBA command button

Posted on 2013-11-19
Last Modified: 2013-11-19
Here's what I am trying to do. Users have to choose between two possible answers - Answer A or Answer B based upon the results of their formulas and interpretation of the results. Answer A and Answer B are command buttons.

I am using the command buttons to test the results of two cells B9 and D9. For example if D9 = $7,500 and B9 = $5,000 then B9 is < D9 and the user should select Answer A. I need a message box that states, "Correct because the cash outlay is $2,500 less!"
However, if that was not true and the user selected Answer A then the message box would state "Incorrect because the cash outlay is $2,500 more!"
My code below for Answer A just is not getting me there.

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

Open in new window

Question by:Frank Freese
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
  • 2
  • 2
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39660228
What are you getting?
LVL 47

Accepted Solution

Martin Liss earned 500 total points
ID: 39660233
Private Sub cmdInvestmentA_Click()
If Range("B9") < Range("D9") Then
MsgBox "Correct because the total cash outlay is " & Range("B9")  - Range("D9") & " less!"
MsgBox "Incorrect because the total cash out is " & Range("D9") - Range("B9")  & " more!"
End If
End Sub

Open in new window


Author Comment

by:Frank Freese
ID: 39660270
Thanks - - -

Author Closing Comment

by:Frank Freese
ID: 39660271
great job!
LVL 47

Expert Comment

by:Martin Liss
ID: 39660283
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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 will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

726 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