How To Display Warning/Alert Messages If Cells Are Blank In Excel?


Excel is a sophisticated data management and analysis application with a variety of features that can boost your productivity. When certain conditions are satisfied, one such capability is the ability to display warning or alert messages. In this article, we'll look at how to use Excel to generate a warning or alert message when cells are left blank. Blank cells frequently result in errors or inadequate data analysis. You can prevent essential cells from being left blank by setting up warning messages that ask users to fill them out before proceeding. This capability is especially handy for constructing forms, gathering data, or creating templates that require precise cell input.

Display Warning/Alert Messages If Cells Are Blank

Here, we will first create a VBA module and then run it to complete the task. So let us see a simple process to know how you can display warning or alert messages if cells are blank in Excel.

Step 1

Consider an Excel sheet where the data in the sheet is similar to the below image.

First, right−click on the sheet and click on View Code to open the VBA application, then click on Insert and select Module.

Right click > View code > Insert > Module.

Step 2

Then copy the below code into the text box.

Code

Sub BlackCell()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Display warning message"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set WorkRng = WorkRng.SpecialCells(xlCellTypeBlanks)
If Err = 0 Then
MsgBox "You don't answer all of questions!"
End If
End Sub

Step 3

Then save the sheet as a macro−enabled template and click F5 to run the module. Then select the range of cells and click OK to complete the task.

Save > F5 > Select range > Ok.

The error message will be displayed.

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can display warning or alert messages if cells are blank in Excel to highlight a particular set of data.

Updated on: 12-Jul-2023

422 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements