Preventing File Closing if certain cells are empthy

JohnH

New Member
Joined
Feb 26, 2002
Messages
3
Is there a way to prevent the user from exiting or saving a file if certain cells are empty? I am creating a template to move data into a database but I want to make sure the user has entered all the required fields before saving and exiting the program.

Thanks.

John
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Sure...
You did not give any details...
This will not allow an exit if there is
nothing in sheet1 Cell A1...
It will select the cell in question as well.
You could test a range, mutliple ranges, data types, formats, ect...<pre>

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheet1.Cells(1, 1) = Empty Or Sheet1.Cells(1, 1) = "" Then
Cancel = True
MsgBox "Required field missing"
Sheet1.Cells(1, 1).Select
End If
End Sub</pre>
This message was edited by TsTom on 2002-04-30 08:40
 
Upvote 0
Try this. JSW

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim mySel
'Works in "ThisWorkBook" module.
'Only if cell has value will the Save or SaveAs utility open.
'If cell has no value, no "SaveAs" is acknowledged.
'If cell has no value "Save" by choice only.
If Sheets("Sheet1").Range("A1") = "" Then
mySel = MsgBox("Do you really want to save the workbook," & Chr(13) _
& "the required cell A1 is empty?", vbYesNo)
If mySel = vbNo Then Cancel = True
End If
End Sub

The above code is safe.

The code below, will prevent a "Close" if the condition is not met, so use caution!

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Prevent workbook close if cell is empty.
If Sheets("Sheet1").Range("A1") = "" Then Cancel = True
End Sub
 
Upvote 0
Do you think is any way to:

Prevent a worksheet/file to print if certain cells are empty?
 
Upvote 0
I put this code but its not working can you please send me any sample file with this code.
E-mail Id:sarapjit@gmail.com
 
Upvote 0
I put this code but its not working can you please send me any sample file with this code.
E-mail Id:sarapjit@gmail.com
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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