title: Checking on empty (not filled) records in Excel Worksheet
body: <p>I have excel Worksheet where I used the following vba code, to check on empty records:</p>
  <pre><code>     Private Sub Workbook_BeforeClose(Cancel As Boolean)
       On Error GoTo NoBlanks
    
       Dim sh As Worksheet, lastRow As Long, lastCol As Long, emptyCells As Range
  
      Set sh = ActiveSheet 'use here your sheet
      lastRow = sh.Range(&quot;A&quot; &amp; Rows.Count).End(xlUp).Row
      lastCol = sh.Cells(1, Columns.Count).End(xlToLeft).Column
  
      Set emptyCells = sh.Range(sh.Cells(1, 1), sh.Cells(lastRow, 
                                                         lastCol)).SpecialCells(xlCellTypeBlanks)
      If emptyCells.Cells.Count &gt; 0 Then
      MsgBox &quot;There are empty cells, which must be filled: &quot; &amp; emptyCells.Address(0, 0)
      emptyCells.Select
      Else
         Resume Next
     Exit Sub
   End If
  
    NoBlanks:
       Resume Next
  
    End Sub
  </code></pre>
  <p>But it still lets me exit out of the Worksheet, even if there empty records</p>
  <p>Are there any ways to modify this code - so it wouldn't be possible to close my Worksheet before the records are filled with values?</p>
  <p>(I used this code on &quot;Before Close&quot; event)</p>