If - Else VBA Code Not Working Why?

SallyMcK

New Member
Joined
Nov 21, 2017
Messages
7
I cannot get the macro to work as I want. I cannot get the MsgBox "Check Columns H and AA before Saving and Sending" to come up if No is Selected if I use the code below.

Code Showing No MsgBox
Code:
Sub SavecheckCL()
'
' SavecheckCL Macro
'


    ActiveWorkbook.Save
    
 Dim AnswerCL As vbmsgboxresult
    
 AnswerCL = MsgBox("Have you checked Supplier Item Number and National Ranging?", vbYesNo, "FINAL CHECK")
 If Answer = vbYes Then
 ActiveWorkbook.Save
 ElseIf Answer = vbNo Then
   MsgBox "Check Columns H and AA before Saving and Sending"
   ActiveWorkbook.Save
 End If


End Sub

Otherwise if I use the following code it displays the msgbox whether I select Yes or No. Where am I going wrong?

Code Showing MsgBox for Both Yes and No
Else
MsgBox "Check Columns H and AA before Saving and Sending"
ActiveWorkbook.Save
 
Last edited by a moderator:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this.
Rich (BB code):
If AnswerCL = vbYes Then
    ActiveWorkbook.Save
ElseIf AnswerCL = vbNo Then
    MsgBox "Check Columns H and AA before Saving and Sending"
    ActiveWorkbook.Save
End If
 
Upvote 0
You "Dim"ed "AnswerCL" and you're using "Answer".

Oops, too slow :)

That's what I get for getting up in the middle of posting.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,941
Members
449,480
Latest member
yesitisasport

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