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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Change
Code:
If ans = vbYes & IsEmpty(M6) Then

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

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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