ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Mandatory Field in Excel 2002 (https://www.excelbanter.com/excel-programming/397307-mandatory-field-excel-2002-a.html)

Somewhere In Excel 2002

Mandatory Field in Excel 2002
 
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?

Mike H

Mandatory Field in Excel 2002
 
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

"Somewhere In Excel 2002" wrote:

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?


Dave Peterson

Mandatory Field in Excel 2002
 
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.

Somewhere In Excel 2002 wrote:

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?


--

Dave Peterson


All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com