Save excel file based on a cell condition

russelldt

Board Regular
Joined
Feb 27, 2021
Messages
160
Office Version
  1. 365
Platform
  1. MacOS
I want to be able to save an excel file, only when specific data have been entered

I can create an if(and( formula to validate the input that is required, and place the result “1” in cell A1. If cell A1 is 1, the file can be saved, (not save as). If cell A1 is ‘0’, a message should appear to complete data in the cells.

Thanks
 
It will be with if you add the "Application.quit" code.

VBA Code:
Sub Workbook_BeforeSave()
If Sheets("Sheet1").Range("A1") = 1 Then
    ActiveWorkbook.Save
    Application.Quit
Else
    MsgBox "You are missing data"
End If
End Sub
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Many thanks
Hello,

I have encountered a small problem with this macro. I often have more than one file open at the same time. When i activate the macro in the file i am working with (call it File 1), the file saves, and closes, but then I get a popup that prompts me to save the next open file (say File 2). If i chose not to save File 2 (i.e. select Cancel), the original file (File 1) does not save and returns.

I would appreciate if you could have a look at this and help with a solution that only closes the file i am actually working on, not any other open files.

Thank you
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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