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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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