How to prevent blank or missing entries in cells in Excel?
Supposing you are creating a table in range A1:B10 of a worksheet and need to prevent blank cell appearing in this table range, how to achieve it? This article introduces a method to automatically pop up prompt box if blank entry appearing in a certain table range while editing. Please follow the method step by step in the article.
Recommended Excel Productivity Tools
A1:B10 is the range where you need to create table inside, and A1, B1 contain the headers of the table as below screenshot shown. Please do as follows to prevent blank or missing entries appearing in range A2:B10 while creating the table.
1. In the worksheet which you won’t allow blank entries in certain range, right click the sheet tab, and then click View Code from the right-clicking menu.
2. In the Microsoft Visual Basic for Applications window, copy and paste the below VBA code into the Code window. See screenshot:
VBA code: Prevent blank or missing entries in a range of cells
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Count <> 1 Then Exit Sub Dim isect As Range On Error Resume Next Set isect = Application.Intersect(Target, Range("A2:B10")) If Not (isect Is Nothing) Then If Target.Column = 1 Then If Len(Target.Value) > 0 And Len(Target.Offset(-1, 0).Value) = 0 Then MsgBox "You cannot skip a row in column A2:B10", vbInformation, "Kutools for Excel" Target.ClearContents End If Else If (Len(Target.Value) > 0 And Len(Target.Offset(-1, 0).Value) = 0) Or (Len(Target.Value) > 0 And Len(Target.Offset(0, -1).Value) = 0) Then MsgBox "You cannot skip a row in column A2:B10", vbInformation, "Kutools for Excel" Target.ClearContents End If End If End If End Sub
Note: In the VBA code, A2:B10 is the range of cells which you don’t want to leave any empty cell inside. Please change the range as you need.
From now on, when you skipping blank cell and fill in the next cell in the specified range directly, you will get a Kutools for Excel dialog box as below screenshot shown.
- How to prevent data entry into specific cells of a worksheet in Excel?
- How to prevent selection of multiple worksheets in Excel?
- How to prevent a certain worksheet from being deleted in Excel?
- How to prevent specific cell contents from being deleted in Excel?