Mandatory Field in Excel 2002

G

Guest

How do you set up a cell to make it a mandatory field so that if anyone fails
to enter a data in a cell or leaves it blank upon closing the worksheet, it
would prompt the user to enter data as it is a mandatory field?
 
G

Guest

One way:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Sheets("Sheet1").Range("A1").Value = "" Then
MsgBox "you must enter data in A1"
Cancel = True
Sheets("Sheet1").Select
Range("A1").Select
End If
End Sub


Mike
Mike
 
D

Dave Peterson

I've never been a fan of putting stuff in the workbook_beforeclose event.

If I open the workbook in error (or just don't want to save my changes), are you
going to make me enter stuff into the workbook just so I can close it?

And if I have to enter stuff in the workbook, are you going to make me save the
workbook before I can close it? What happens if I open the workbook and destroy
18 worksheets that are very important. If I try to close it, are you going to
force me to save it this way?

Personally, I'd try to do something else.

I like to add a warning message in a cell based on a formula:
=if(somethingisok,"","Warning--xxx and yyy have to be done first!")
(formatted in big bold red letters)

Then I as a user can see the warning and still be able to close without
saving--or close and save and fix at a later time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top