create required field in excel sheet/form

K

K. Elliot

I am wondering if there is an easy way to make certain fields within
an excel sheet required. I would like excel to display a message that
there were certain required fields that were left blank (and not be
able to close the file without the required fields).

I came across an item posted to this newsgroup on october 8, 2002 from
hank scorpio, but was unable to get it to work using the script he
posted.

Any assistance is greatly appreciated. Thanks.

Kevin
 
B

Bob Umlas

In the Workbook_BeforeClose event:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Application.CountA(Range("A3,B5,G4:G6")) <> 5 Then 'note there are
5 cells in this range -- adjust them to be YOUR required fields
MsgBox "required fields missing" 'Note-- maybe you want to
select them here as well
Cancel = True
End If
End Sub

Bob Umlas
Excel MVP
 
Top