Saving Spreadsheets

Sergio_Montenegro

Board Regular
Joined
Feb 23, 2008
Messages
108
Hi folks, is there any way in which I can make sure that a spreadsheet cannot be saved unless specific cells have data or information entered...

For example if A1 has to have 100 entered and B2 has to have 200 entered, if I try and save it, I get a message that says "Some information is missing, please ensure all appropriate cells are competed correctly" or womething like that... I hope this makes sense.

Thanks in advance

Serge
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,772
Paste into 'ThisWorkbook' module...

Change "Sheet1" to the name of the sheet in question...

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    With Sheets("Sheet1")
        If .Range("A1") <> 100 Or .Range("B2") <> 200 Then
            MsgBox "Some information is missing, please ensure all appropriate cells are competed correctly", vbCritical, "Oops!!"
            Cancel = True
        End If
    End With
End Sub
 

Magriza

Well-known Member
Joined
Nov 16, 2005
Messages
508
Also change the
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
to read
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

The above will fire when the user tries to print, not save....
 

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,772
Well spotted - thanks for the correction!

Also change the
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
to read
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

The above will fire when the user tries to print, not save....
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,282
Messages
5,836,392
Members
430,425
Latest member
xlsee

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
Top