Make Cells Mandatory Before Saving an Excel Template
Question details
The user wants required cells in an Excel template to be completed before the workbook is saved or submitted.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Users fill out an Excel template that contains mandatory fields.
- Observed behavior
- Excel has no universal built-in setting that blocks saving when required cells are blank.
Identify the worksheet name and cell addresses that must be completed. For a VBA save check, use desktop Excel and make sure users can enable macros from a trusted source.
Block saving with a Workbook_BeforeSave macro
Use this method in desktop Excel when a save should be canceled if specified cells are blank.
The example checks cells B2, B4, and B6 on a sheet named Form. Change the sheet name and addresses to match your template.
The check counts empty cells and formulas that return an empty string as blank. It does not reject cells containing only spaces.
In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm).
Open the Developer tab, select Visual Basic, and double-click ThisWorkbook in the project pane. If Developer is hidden, enable it in Excel's ribbon settings.
Paste this code into the ThisWorkbook code window: Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim cell As Range For Each cell In ThisWorkbook.Worksheets("Form").Range("B2,B4,B6").Cells If Application.WorksheetFunction.CountBlank(cell) > 0 Then MsgBox "Complete all required fields before saving.", vbExclamation Cancel = True Exit Sub End If Next cell End Sub
Return to Excel and select Save with a required cell blank; the message should appear and the save should be canceled. Complete all required cells and select Save again.
Label the required fields clearly. If needed, use Review > Protect Sheet to protect the layout, leaving input cells unlocked before applying protection.

Guide users with data validation
Use data validation to warn users about invalid entries when blocking the workbook save is not essential.
Edit spreadsheet templates with WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files and continue working with templates while making a straightforward transition from Microsoft Office.

Frequently Asked Questions
Can Excel prevent saving when required cells are blank without VBA?
Excel has no universal built-in setting for this. Data validation can guide users, but a VBA save check or controlled submission workflow is needed for stronger enforcement.
Where do I put the Workbook_BeforeSave code?
In desktop Excel, open Developer > Visual Basic and paste the event code into the ThisWorkbook module for the template.
Will the save macro work in Excel for the web?
No. Excel for the web does not run VBA macros. Use desktop Excel with macros enabled or choose a separate controlled submission process.
Does protecting the worksheet make required cells mandatory?
No. Review > Protect Sheet can protect the layout, but it does not check whether required cells are filled. Leave input cells unlocked before protecting the sheet and use a separate validation or save check.




