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
 
I added the VBA to the ThisWorkbook and when i run it, the Macro Name window pops up
I dont really understand what you mean.
I added the VBA script to the Thisworkbook section.

When I run test/run the script in the VBA module, the ’MacroName‘ window opens - it wants to run a macro. I tried to upload a screen shot, but the file 840 kb is too large. I hope this makes more sense, thanks
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Yes. There is another one, to
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge = 1 Then
If Target.Column = 11 And Target.Row > 8 And Target.Row < 63 Then
If Target.Value = "" Then
Target.NumberFormat = "General"
ElseIf Target.Value <= Date Then
Application.EnableEvents = False
Target.Value = DateAdd("yyyy", 1, Target.Value)
Application.EnableEvents = True
End If
End If
End If
End Sub
 
Upvote 0
I don't see how that might interfer with the save macro.

Hopefully someone else can figure it out, otherwise I'll try again tomorrow. It's getting late here. :)
 
Upvote 0
I don't see how that might interfer with the save macro.

Hopefully someone else can figure it out, otherwise I'll try again tomorrow. It's getting late here. :)
I am working on Mac OS. That is often the source of the problem.
 
Upvote 0
Thanks PC master?

In the meantime I will go with your first suggestion and add a Macro button on the sheet to save the file. One question, can/will this close the file after saving? That would be a great help if I could click the macro button, and it will save and close.
 
Upvote 0
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

Forum statistics

Threads
1,224,817
Messages
6,181,149
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