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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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