In Excel, how to make a field required so it's not left blank?

L

linplex

I've seen a lot of advise, however I need complete, step-by-step
instructions. Thanks!
 
C

Chip Pearson

I assume you want to ensure that a cell is filled out before the
workbook is closed. Open the VBA Editor, display the Project
Window (CTRL+R) and open the ThisWorkbook code module. There,
paste the following code:


Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("Sheet1").Range("A1").Value = "" Then
MsgBox "You must fill in A1."
Cancel = True
End If
End Sub


Change the Sheet name and cell reference to meet your needs.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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