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
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,764
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,764
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....
 

Watch MrExcel Video

Forum statistics

Threads
1,123,530
Messages
5,602,200
Members
414,513
Latest member
junbuggle

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