how to have fields to be required

  • Thread starter Mandatory fields in Excel
  • 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?
 
G

Gord Dibben

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
 

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