Solved

Evaluating two cells with VBA command button

Posted on 2013-11-19
5
238 Views
Last Modified: 2013-11-19
Folks,
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!"
Else
MsgBox "Incorrect because the total cash out is " & D9 - B9 & " more!"
End If
End Sub

Open in new window

0
Comment
Question by:Frank Freese
  • 2
  • 2
5 Comments
 
LVL 43

Expert Comment

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

Accepted Solution

by:
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!"
Else
MsgBox "Incorrect because the total cash out is " & Range("D9") - Range("B9")  & " more!"
End If
End Sub

Open in new window

0
 

Author Comment

by:Frank Freese
ID: 39660270
Thanks - - -
0
 

Author Closing Comment

by:Frank Freese
ID: 39660271
great job!
0
 
LVL 45

Expert Comment

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

Marty - MVP 2009 to 2013
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now