VBA to Save and Close based on a Cell having/not having data in it

Nutterhead

New Member
Joined
Apr 25, 2017
Messages
27
Hello wonderful helpers,

I have a VBA code I'm trying to write that will allow users to click a button and that will save and close the workbook every time but if it's the final save for the end of the day will look at cell M6 to see if it's empty or not. If it's empty I need the sub to exit without saving and closing giving a message that it must have a verification name. The Cell does not have a formula or anything in it but is based off a data validation list. I can't seem to figure it out correctly below is what I currently have.

Sub Save_and_Close()

Dim ans As String, lr As Long

ans = MsgBox("Is this the final save before upload?", vbYesNo)
If ans = vbYes & IsEmpty(M6) Then
MsgBox ("Must Have Verification Name")
Exit Sub
Else
ThisWorkbook.Save
MsgBox ("Your data has been saved."), vbInformation
Application.Quit

End If
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Change
Code:
If ans = vbYes & IsEmpty(M6) Then

To
Code:
If ans = vbYes And IsEmpty(M6) Then
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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