Message Box Help (VBA)

Deuce Bucksman

Board Regular
Joined
Jan 17, 2011
Messages
102
Hello gurus!
I apologize if this is an asinine question, but is there anyone who could please tell me what I'm doing wrong with the code below. I'm trying to have the message box respond with a different message depending on which button the user selects (Yes/No). I tried to figure this out before coming to the board, but was unsuccessful. Everything works up until the ELSE statement. Thanks for your assistance.



Sub MacroTest1()
Dim x As Variant
Dim y As Variant
Dim answer As Variant

x = InputBox("Enter a number.", "Number entry one.")
y = InputBox("Enter another number.", "Number deuce.")
answer = WorksheetFunction.Sum(x, y)
MsgBox "Your answer is " & answer & "!", vbYesNo, "Your answer."
If vbYes Then
MsgBox ("Good times.")
Else: If vbNo Then MsgBox ("great times.")

End If
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Code:
Sub MacroTest1()
    Dim x As Variant
    Dim y As Variant
    Dim answer As Variant
    Dim Reply As Long
    
    x = InputBox("Enter a number.", "Number entry one.")
    y = InputBox("Enter another number.", "Number deuce.")
    answer = WorksheetFunction.Sum(x, y)
    Reply = MsgBox("Your answer is " & answer & "!", vbYesNo, "Your answer.")
    If Reply = vbYes Then
        MsgBox ("Good times.")
    ElseIf Reply = vbNo Then
        MsgBox ("great times.")
    End If
End Sub
 
Upvote 0
Here's a start - Note RED


Sub MacroTest1()
Dim x As Variant
Dim y As Variant
Dim answer As Variant
Dim res
x = InputBox("Enter a number.", "Number entry one.")
y = InputBox("Enter another number.", "Number deuce.")
answer = WorksheetFunction.Sum(x+0, y+0)
res = MsgBox ("Your answer is " & answer & "!", vbYesNo, "Your answer.")
If vbYes Then
MsgBox "Good times." 'Removed ()
Else: If vbNo Then MsgBox "great times." 'Removed ()
End If
End Sub
 
Upvote 0
Thanks! Works perfectly. I'm still learning this process so I see I omitted some very neccessary steps. Thanks for the quick response.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,736
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top