how to have fields to be required

  • Thread starter Thread starter Mandatory fields in Excel
  • Start date Start date
M

Mandatory fields in Excel

I have an excel sheet that has fields we need to enter, (i.e. zipcode, State,
City), and what I want to know is HOW do I have it "mandatory" to have those
fields filled? Meaning if someone only fills 1 out of the 3 fields, then
tries to save it, it should prompt something like, "Please fill all fields
before saving", or something like that?
 
You would need event code to cancel the save if all three cells were not filled.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
If Application.CountA(Sheets("Sheet1").Range("A1:C1")) < 3 Then
Cancel = True
MsgBox "Please fill required cells, save has been cancelled"
End If
End Sub

Note: if user disables macros the above won't run.


Gord Dibben MS Excel MVP
 
Back
Top