Avatar of Frank Freese
Frank Freese
Flag for United States of America asked on

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

Microsoft Excel

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
Saqib Husain

What are you getting?
ASKER CERTIFIED SOLUTION
Martin Liss

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Frank Freese

ASKER
Thanks - - -
Frank Freese

ASKER
great job!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Martin Liss

You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013