Template Issues

Make Cells Mandatory Before Saving an Excel Template

Bushra ParveenBushra Parveen Nov 18, 2026 868 views

Question details

The user wants required cells in an Excel template to be completed before the workbook is saved or submitted.

Make Cells Mandatory Before Saving an Excel Template
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.
Before you start

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.

Solution 1Recommended

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.

1
Save as a macro-enabled workbook

In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm).

2
Open the workbook code

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.

3
Add the save check

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

4
Test the check

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.

5
Prepare the template for users

Label the required fields clearly. If needed, use Review > Protect Sheet to protect the layout, leaving input cells unlocked before applying protection.

Block saving with a Workbook_BeforeSave macro
Macro limitations: VBA does not run in Excel for the web. Users who disable macros can bypass this check, so use a controlled submission process if enforcement must be reliable.
Free Microsoft Office alternative

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.

Edit and label required fields in spreadsheet templates.Open and save common Microsoft Excel formats, including XLSX and XLS.Use a familiar interface for everyday spreadsheet work.Move existing compatible spreadsheets into a lightweight office suite.
microsoft office alternative - wps 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.