• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

Evaluating two cells with VBA command button

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
Frank Freese
Asked:
Frank Freese
  • 2
  • 2
1 Solution
 
Saqib Husain, SyedEngineerCommented:
What are you getting?
0
 
Martin LissRetired ProgrammerCommented:
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
 
Frank FreeseAuthor Commented:
Thanks - - -
0
 
Frank FreeseAuthor Commented:
great job!
0
 
Martin LissRetired ProgrammerCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now